Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
csv info to excel
I am brand new to VBA and have a beginner level knowledge of Visual Basic 6.0
I was assigned a task recently for Excel that exceeds my knowledge of VBA and Excel by far. what i need to do is make an existing file read a .csv file and add the quantity. for example. Excell File. Item Number | Description | Quantity | 0003635457 | Vcr's | 0 | 8848483748 | DVD | 3 | 8837267499 | Reciever | 14 | etc. ..csv File. ItemNumber, Quantity 83836464985, 4 83984959489, 12 28498748793, 9 etc. i want to search the csv file for each ItemNumber (I know how to do basic Naming of Cells) and then update the quantity in the Excell file. I'd also like to say I am not one of these people too incompetent to learn, I am learning VBA now from the beginning, but I just have a deadline with this particular task. hehe. Any help would be greatly appreciated |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
csv info to excel
This might get you started:
Option Explicit Sub testme() Dim myRng As Range Dim myCell As Range Dim curWks As Worksheet Dim csvRng As Range Dim res As Variant Set curWks = ActiveSheet Set csvRng = Workbooks.Open(Filename:="C:\my documents\excel\book5.csv") _ .Worksheets(1).Range("a:a") With curWks Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp)) For Each myCell In myRng.Cells res = Application.Match(myCell.Value, csvRng, 0) If IsError(res) Then 'no match found Else If IsNumeric(csvRng(res).Offset(0, 1).Value) _ And IsNumeric(myCell.Offset(0, 2)) Then myCell.Offset(0, 2).Value _ = myCell.Offset(0, 2).Value _ + csvRng(res).Offset(0, 1).Value Else MsgBox "nonnumeric data in: " & myCell.Row & _ vbLf & "or in the CSV file line: " & res End If End If Next myCell End With csvRng.Parent.Parent.Close savechanges:=False End Sub Thomas DeFrank wrote: I am brand new to VBA and have a beginner level knowledge of Visual Basic 6.0 I was assigned a task recently for Excel that exceeds my knowledge of VBA and Excel by far. what i need to do is make an existing file read a .csv file and add the quantity. for example. Excell File. Item Number | Description | Quantity | 0003635457 | Vcr's | 0 | 8848483748 | DVD | 3 | 8837267499 | Reciever | 14 | etc. .csv File. ItemNumber, Quantity 83836464985, 4 83984959489, 12 28498748793, 9 etc. i want to search the csv file for each ItemNumber (I know how to do basic Naming of Cells) and then update the quantity in the Excell file. I'd also like to say I am not one of these people too incompetent to learn, I am learning VBA now from the beginning, but I just have a deadline with this particular task. hehe. Any help would be greatly appreciated -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
i deleted info in excel then saved. can i recover deleted info? | Excel Discussion (Misc queries) | |||
Copied info from Excel worksheet, but pasted info won't work in fo | Excel Discussion (Misc queries) | |||
Link info in one cell to info in several cells in another column (like a database) | Excel Discussion (Misc queries) | |||
Can I lock info in Excel 2003 and users in Excel 2000 enter info? | Excel Discussion (Misc queries) | |||
how do i get excel to see info in one cell, look at info in anoth. | Excel Discussion (Misc queries) |