csv info to excel

  • Thread starter Thread starter Thomas DeFrank
  • Start date Start date
T

Thomas DeFrank

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top