Hello All,
I'm trying to have a excel execute a simple procedure to copy and paste some cell ranges from one workbook to another. The code runs correctly up to a point but then doesn't execute a line as expected and then randomly jumps back 10 or so lines in the code (rather than continuing line by line as I would expect?). The relevant pieces of the code are below:
Dim WB_Masterlist As Workbook
Dim WB_Source2 As Workbook
......
'4.Prompts user to select the source file from dropdowns
'Assigns the name WB_Source to the file the user selects
Filt = "Excel Files (*.xls),*.xls"
Title = "Please select the Source File"
WB_Source = Application.GetOpenFilename _
(FileFilter:=Filt, _
Title:=Title)
'5.Opens the source workbook
Workbooks.Open Filename:=WB_Source
Set WB_Source2 = ActiveWorkbook
..........
'13.Enter End Date into cell C6
Range("C6").Value = EndDate
'14.Sets the variable names that are used to save the worksheet with the correct name
Barname = WB_Source2.Sheets("Set").Range("B4").Value
Startdate = WB_Saru_count2.Sheets("Dates").Range("C5").Text
EndingDate = WB_Saru_count2.Sheets("Dates").Range("C6").Text
'15.Load the masterlist
ChDir "C:\Bar-i\Tools"
Workbooks.Open Filename:= _
"C:\Bar-i\Clients\DropBox\Bar-i Masterlist.xls"
Set WB_Masterlist = ActiveWorkbook
Range("A1:Q5300").Select
Application.CutCopyMode = False
Selection.Copy
WB_Saru_count2.Activate
Sheets("Mast").Select
Range("A1").Select
ActiveSheet.Paste
WB_Masterlist.Activate
Sheets("Sheet1").Select
Range("A6000").Select
'The previous line to this one does not execute?
Selection.End(xlDown).Select
ActiveCell.Range("A1:B100").Select
Selection.Copy
'After this line it randomly jumps up to the line:
'13.Enter End Date into cell C6
Range("C6").Value = EndDate
I'm stuck! Any help is greatly appreciated!
I'm trying to have a excel execute a simple procedure to copy and paste some cell ranges from one workbook to another. The code runs correctly up to a point but then doesn't execute a line as expected and then randomly jumps back 10 or so lines in the code (rather than continuing line by line as I would expect?). The relevant pieces of the code are below:
Dim WB_Masterlist As Workbook
Dim WB_Source2 As Workbook
......
'4.Prompts user to select the source file from dropdowns
'Assigns the name WB_Source to the file the user selects
Filt = "Excel Files (*.xls),*.xls"
Title = "Please select the Source File"
WB_Source = Application.GetOpenFilename _
(FileFilter:=Filt, _
Title:=Title)
'5.Opens the source workbook
Workbooks.Open Filename:=WB_Source
Set WB_Source2 = ActiveWorkbook
..........
'13.Enter End Date into cell C6
Range("C6").Value = EndDate
'14.Sets the variable names that are used to save the worksheet with the correct name
Barname = WB_Source2.Sheets("Set").Range("B4").Value
Startdate = WB_Saru_count2.Sheets("Dates").Range("C5").Text
EndingDate = WB_Saru_count2.Sheets("Dates").Range("C6").Text
'15.Load the masterlist
ChDir "C:\Bar-i\Tools"
Workbooks.Open Filename:= _
"C:\Bar-i\Clients\DropBox\Bar-i Masterlist.xls"
Set WB_Masterlist = ActiveWorkbook
Range("A1:Q5300").Select
Application.CutCopyMode = False
Selection.Copy
WB_Saru_count2.Activate
Sheets("Mast").Select
Range("A1").Select
ActiveSheet.Paste
WB_Masterlist.Activate
Sheets("Sheet1").Select
Range("A6000").Select
'The previous line to this one does not execute?
Selection.End(xlDown).Select
ActiveCell.Range("A1:B100").Select
Selection.Copy
'After this line it randomly jumps up to the line:
'13.Enter End Date into cell C6
Range("C6").Value = EndDate
I'm stuck! Any help is greatly appreciated!