F8 jumps to end of my code

Mariappan

New Member
Joined
Apr 1, 2021
Messages
2
Office Version
  1. 365
When i use F8 to test my code and whenever i cross the below line my code jumps to the end of my code. Please can someone assist.

filetoopen = Application.GetOpenFilename(Title:="browse for your file & import range", Filefilter:="Excel Files(*.xls*),*xls*")
If filetoopen <> False Then
Set openbook = Application.Workbooks.Open(filetoopen)
End If

Thanks
Mariappan
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,993
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Board!

I think we need to see the rest of your code, to see where exactly this is in relation to everything else, and if there is an Error Handling code built-in.

When posting your code, please use Code Tags, a described here: How to Post Your VBA Code
 

mart37

Well-known Member
Joined
Aug 4, 2017
Messages
1,091
Office Version
  1. 2016
Platform
  1. Windows
"Excel Files(*.xls*)"
 

Mariappan

New Member
Joined
Apr 1, 2021
Messages
2
Office Version
  1. 365
Hi Joe4,

Thanks for getting back. Please find the full code below. The bold highlighted line is where my code jumps till end when i press F8. Kindly assist.

VBA Code:
Sub summary()
Dim newworkbook As Workbook
Dim filetoopen As Variant
Dim openbook As Workbook
Dim wb As Workbook
Application.ScreenUpdating = False
Dim dattym As String
Dim lrow As Long
Dim lcol As Long
Dim rownum As Long
Dim list As Variant
Dim stdat As Date
Dim endat As Date
dattym = Format(CStr(Now), "YYYY-mm-dd")
Set newworkbook = Workbooks.Add
With newworkbook
    .Title = file name
    .SaveAs Filename:="D:\localhome\username\Desktop\folder name\" & "Pjm Training Summary - " & dattym
    .Close
    
End With

[QUOTE]
[B]filetoopen = Application.GetOpenFilename(Title:="browse for your file & import range", Filefilter:="Excel Files(*.xls*),*xls*")[/B]
[/QUOTE]
If filetoopen <> False Then
    Set openbook = Application.Workbooks.Open(filetoopen)
End If

openbook.ActiveSheet.Range("A5").CurrentRegion.Copy
Workbooks.Open("D:\localhome\username\Desktop\folder name\" & "file name- " & dattym).Activate
'Range("A1").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, none

Range("A5").PasteSpecial xlPasteAllUsingSourceTheme, xlPasteSpecialOperationNone, none
Selection.Columns.AutoFit
ActiveWorkbook.Save
ActiveWorkbook.Close
Workbooks.Open Filename:=("D:\localhome\user name\Desktop\file name")
lcol = WorksheetFunction.CountA(Range("G3", Range("G3").End(xlDown)))
list = Range(Cells(3, 7), (Cells(lcol + 2, 7))).Value
list = Application.Transpose(list)
list = Join(list, ",")
list = Split(list, ",")
list = Split(Join(Application.Transpose(Range(Cells(3, 7), Cells(lcol + 2, 7)).Value), ","), ",")
Workbooks.Open Filename:=("D:\localhome\mariappana\Desktop\Pjm Training Summary")
stdat = ActiveWorkbook.ActiveSheet.Cells(3, 8).Value
endat = ActiveWorkbook.ActiveSheet.Cells(3, 9).Value
Workbooks.Open("D:\localhome\mariappana\Desktop\PJM Training Week March\" & "Pjm Training Summary - " & dattym).Activate
 
With Selection
    .AutoFilter Field:=14, Criteria1:=list, Operator:=xlFilterValues
    
    .AutoFilter Field:=17, Criteria1:="<=" & CDbl(endat), Operator:=xlAnd, Criteria2:=">=" & CDbl(stdat)
         
            
End With

Application.ScreenUpdating = False
    
Sheets.Add.Name = "Data"
Sheets(1).Range("A5").CurrentRegion

Selection.Copy Destination:=Sheets("Data").Range("A5")
Selection.Columns.AutoFit
'Worksheets("Data").Range("A2").Value = "title of report " & dattym

Selection.Copy Destination:=Sheets("Data").Range("A5")
Selection.Columns.AutoFit


End Sub
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,993
Office Version
  1. 365
Platform
  1. Windows
I cannot reproduce that error. It goes on past that line and continues with the code when I test it out.

If there is an error, it should pop up, unless you suppressed messages.
Try running this little macro first, and then try running your code again:
VBA Code:
Sub ResetThings()
    On Error GoTo 0
    Application.DisplayAlerts = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,130,083
Messages
5,639,977
Members
417,120
Latest member
Pavithra devi

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
Top