ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   csv info to excel (https://www.excelbanter.com/excel-programming/302540-csv-info-excel.html)

Thomas DeFrank

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

Dave Peterson[_3_]

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



All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com