Run-time Error '438': with CSV file

Woftae

New Member
Joined
Feb 10, 2018
Messages
16
My fellow excelorians, I am trying to reference a CSV file via my macro but keep getting the Run-time Error '438':
I have tried various code changes to try and resolve the issue without success.
It appears that the sheet name "order_items_Orders" from the CSV files is not being allocated to the variable "wsCSV"
Thanks in advance for any assistance.

The code I am trying to execute is as follows, it messy at the moment because its not finished:

Public Sub OrdersAutoEntry()
'
' Created by Woftae
'

Dim FilePathCSV As String
'FilePathCSV = "C:\Users\woftae\downloads\order_items_Orders.csv"

'MsgBox ActiveWorkbook.Name & vbNewLine & ActiveWorkbook.Path

Dim wbCSV As Workbook
Set wbCSV = Workbooks.Open(FilePathCSV)

Dim wsCSV As Worksheet
Set wsCSV = wbCSV.Worksheets("order_items_Orders")
'Set wsCSV = Workbooks("order_items_Orders.csv").Worksheets("order_items_Orders")

MsgBox "CSV sheet is: " & wsCSV <<<<<< error occurs here

'Set ws = wb.Sheets(1)

Dim RowCSV As Long 'Orders Exported Sheet Row
RowCSV = 2

Dim wsORDERS As Worksheet
Set wsORDERS = Workbooks("Suppliers Orders V3.xlsm").Worksheets("Orders")

Dim RowORDERS As Long 'Orders Sheet Row
RowORDERS = wsCSV.Range("B" & Rows.Count).End(xlUp).Row + 1 ' Needs to be set to last row of the orders sheet

'MsgBox ActiveWorkbook.Name & vbNewLine & wsCSV

wsCSV.Select

Do While wsCSV.Cells(RowCSV, 2).Value <> "" And wsCSV.Cells(RowCSV, 9).Value <> 0

wsORDERS.Range("B" & RowORDERS).Value = wsCSV.Cells(RowCSV, 2)
wsORDERS.Range("D" & RowORDERS).Value = wsCSV.Cells(RowCSV, 4)
wsORDERS.Range("E" & RowORDERS).Value = wsCSV.Cells(RowCSV, 5)
wsORDERS.Range("F" & RowORDERS).Value = wsCSV.Cells(RowCSV, 6)
wsORDERS.Range("H" & RowORDERS).Value = wsCSV.Cells(RowCSV, 8)
wsORDERS.Range("I" & RowORDERS).Value = wsCSV.Cells(RowCSV, 9)

RowCSV = RowCSV + 1
RowORDERS = RowORDERS + 2

Loop

wsCSV.Cells.Select
Selection.ClearContents

wsCSV.Range("B" & RowORDERS).Select

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
When you post code, please click on the </> icon and post it into the popup window in order to tag it correctly and preserve formatting, thanks :)

wsCSV is an object, a messagebox can only display a string.
VBA Code:
MsgBox "CSV sheet is: " & wsCSV.Name
There may be other errors in your code, I've only looked at the one that you have asked about.
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,554
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top