Compile error: expected end of statement

jfabro

New Member
Joined
May 25, 2014
Messages
10
I am in need of a way to consolidate data from multiple files into one file. I am using the code below to perform this task. There are 2 errors and I am at a loss for how to correct them. Any help would be greatly appreciated.

Sub GetData()Dim strWhereToCopy As String, strStartCellColName As String
Dim strListSheet As StringstrListSheet = "LIST"
On Error GoTo ErrH
Sheets(strListSheet).Select
Range("B2?).Select
'this is the main loop, we will open the files one by one and copy their data into the masterdata sheet
Set currentWB = ActiveWorkbook
Do While ActiveCell.Value <> ""
strFileName = ActiveCell.Offset(0, 1) & ActiveCell.Value
strCopyRange = ActiveCell.Offset(0, 2) & ":" & ActiveCell.Offset(0, 3)
strWhereToCopy = ActiveCell.Offset(0, 4).Value
strStartCellColName = Mid(ActiveCell.Offset(0, 5), 2, 1)
Application.Workbooks.Open strFileName, UpdateLinks:=False, ReadOnly:=True
Set dataWB = ActiveWorkbook
Range(strCopyRange).Select
Selection.Copy
currentWB.Activate
Sheets(strWhereToCopy).Select
lastRow = LastRowInOneColumn(strStartCellColName)
Cells(lastRow + 1, 1).Select
Selection.PasteSpecial xlPasteValues, xlPasteSpecialOperationNone
Application.CutCopyMode = False
dataWB.Close False
Sheets(strListSheet).Select
ActiveCell.Offset(1, 0).Select
Loop



Thank you for assisting me.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
1) No EndSub statement
2)
Code:
Dim strListSheet As StringstrListSheet = "LIST"
should be
Code:
Dim strListSheet As String
strListSheet = "LIST"
3)
Code:
Range("B2?).Select
should be
Code:
Range("B2").Select
 
Upvote 0
I'm not a VBA expert but one of the errors may be:
Range("B2?).select
I must close quotation and not put a question mark...
Shouldn't you define you Error handler?
You just put
On Error Go to ErrH
 
Upvote 0
1) No EndSub statement
2)
Code:
Dim strListSheet As StringstrListSheet = "LIST"
should be
Code:
Dim strListSheet As String
strListSheet = "LIST"
3)
Code:
Range("B2?).Select
should be
Code:
Range("B2").Select


Thank you, that was so simple I should have seen it.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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