473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Updating cells with new data from CSV Files

Hi,

Sorry, this is a bit of a lengthy one but I guess too much information is better than less!

I have an excel worksheet that I update regulary with latest values from downloaded CSV files. Right now, other than a couple of basic recorded macros to clean up the source data CSV files, most of this process is manual and I'l looking to automate it. I'm aware there is quite a bit of code posted on consolidating data but I've not seen anything that will work for me.

Here's my setup.

1) CSV Data Source Files: Have about 15 of these in the same folder. Each file has two columns, first is a date column and the second is values associated with that date. The length/no of rows of the data varies between files and not all files contain matching dates. All dates will have a value associated with it, there are no nulls/blanks.

2) Excel worksheet. This is where I currently update/consolidate the data from the source CSV files. Basicly, column A contains the dates and each successive column holds data relating to a particulary CSV files. When the latest data becomes avaliable I enter the entries in new rows for each variable. I do not erase or overwrite any of the old data, i.e I'm effectively building a timeseries. The actual data for each series starts in row 4. Where there is no value for a series/column for a given date, it is left blank.

The third row of the sheet contains codes relating to the source files. For example b3 = NBU1, this is the same as the corresponding file in the folder - the folder will have a file called NBU1.csv.

There is only one date field in the consolidation sheet (Col A,) and this if you like is my "primary key". If data does not exist in the source file for a particular date then I leave that cell in the column for that indicator blank, if there is data in the source file associated with a date that does not exist in the consolidation sheet (Col A) then I ignore that value and do not copy it over.

So basicly I'm looking for some code that will open each file in the folder, locate the relevant column in the spreadsheet based on the codes in row 3 and then copy over the latest data via I guess mapping the dates in the CSV files and to the dates in column A of the spreadsheet.

Hope someone can help.

Many Thanks,

Lucas
Feb 7 '08 #1
9 2082
kadghar
1,295 Expert 1GB
Hi there.

Call me lazy, but the way I would do it is importing into a sheet all the info from all the CSV, one after other, i. e.

Column A: Dates
Column B: Info
Column C: FileName

And then use the magic of Excel's Pivot Tables.

Could that help?
Feb 7 '08 #2
Killer42
8,435 Expert 8TB
Subscribing .
Feb 8 '08 #3
Hi Gents,

Thanks for your suggestions. The pivot table is a good idea but the only problem is that some of the source files don't contain the entire history but only recent data, hence I'm storing the previous/historical data in the summary sheet and adding the new data to it.

Lucas
Feb 13 '08 #4
poolboi
170 100+
Guys,
sorry to interrupt the discussion but since it's almost similar to my problem
just like to know how do u import yr data from CSV file into yr excel sheet?
i seriously have no idea how that can be done
thanks
Feb 15 '08 #5
Killer42
8,435 Expert 8TB
To get a CSV file into Excel, just open it.
Feb 15 '08 #6
poolboi
170 100+
hm...
opps should be more specific
i need to use perl program to actually help me input datas from csv file to excel file
without all those commas
Feb 15 '08 #7
romcab
108 100+
Hi guys,

I created a simple apps which automate excel file using C#.net. It's quite similar to your problem so I paste here a link where I based my idea and some of my code snippet.

http://www.codeproject.com/KB/cs/Simple_Excel_Automation.aspx


public bool OpenExcel()
{
bool rtn = true;

try
{
m_wb = m_app.Workbooks.Open(m_filename, 0, false, 5, System.Reflection.Missing.Value,
System.Reflection.Missing.Value, false, System.Reflection.Missing.Value,
System.Reflection.Missing.Value, true, false, System.Reflection.Missing.Value,
false, false, false);

m_app.Visible = true;
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
rtn = false;
}

return rtn;
}

public void CloseExcel()
{
m_wb.Save();
m_app.Visible = false;
}

//set sheet to open
public void SetExcelSheet()
{
m_sh = m_wb.Sheets;
}

//Get all reference number on a given sheet
public void GetRefData(int sheet)
{

m_ws = (Worksheet)m_sh[sheet];
for (int i = 5; ; i++)
{
string row = "A" + i + ":" + "A" + i;
Range cell = m_ws.get_Range(row, Type.Missing);

if (cell.Value2 != null)
{
if (sheet == 1)
{
m_array1.Add(cell.Value2.ToString());
}
else
{
m_array3.Add(cell.Value2.ToString());
}
}
else
{
break;
}
}
}
Feb 15 '08 #8
Killer42
8,435 Expert 8TB
hm...
opps should be more specific
i need to use perl program to actually help me input datas from csv file to excel file
without all those commas
No matter what language you drive it from, Excel should have no problem importing a CSV file.

However, this is the Visual Basic forum. You should ask in the Perl forum if you need help with that language.
Feb 17 '08 #9
poolboi
170 100+
opps sorrie
no wonder the language is so weird
i didn't see the visual basic heading on top
sorrie sorrie
Feb 18 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Laphan | last post by:
Hi All I know this is my 2nd (and final) cross-post, but which NG should I use for the below. I want to create a game that queries and updates text and numeric stats on a regular basis, so...
3
by: Sean Lambert | last post by:
We had someone create an extra data file and log file for tempdb. So we currently have two data files and two log files. Is it possible to delete the newly created data and log files? If I just...
2
by: Domenico Discepola | last post by:
Hello all. Before my arrival at my current employer, our consultants physically set up our MSSQL 7 server as follows: drive c: contains the mssql engine drive d: contains the transaction log...
2
by: RickMuller | last post by:
I really appreciate the ease that the distutils make distributing Python modules. However, I have a question about using them to distribute non-Python (i.e. text) data files that support Python...
15
by: Xarky | last post by:
Hi, Is it possible to make use of data files in C? If yes can someone tell how or suggest me a site from where I can learn them. Thanks in Advance for your patience.
13
by: EricJ | last post by:
hi i need to access cobol data files from .net, the files have no or .vix extention (i think thats a acucobol or something like that) (/me has completely no experience in cobol) i heard that...
1
by: Byron | last post by:
Hi, I have(had) an old Win2k Server server with about 30 web site databases (SQL 2000) that just went under due to hardware problems. Thankfully, I have backups of all the databases plus the MDF...
3
by: MF AHMED | last post by:
Hello, I am facing problem writing an algorithm/codes. From a C program, I generated 100 data files, now I have to read those files having three columns each. Using every data of each line of all...
2
by: Gary42103 | last post by:
Hi I need Perl Script to do Data Parsing using existing data files. I have my existing data files in the following directory: Directory Name: workfs/ams Data File Names: 20070504.dat,...
5
by: =?Utf-8?B?VHJhY2tz?= | last post by:
I include some sample binary data files (produced by my software) with my application installation for the user to do what they want with. I put the files in the Users Personal Data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.