• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Coding not crossing line3

Hi All,

There is some problem in coding it goes to line 2 after line 3. I dont know why, might be somebody knows this..
Code:
Sub test()
Dim Last_Row As Double, File_Name As String, sht As Worksheet, Wb As Workbook
File_Name = Application.GetOpenFilename(filefilter:="Excel Files (*.xls*), .xls", Title:="Open Weekly Report - Step 1 of 8")
Workbooks.Open Filename:=File_Name
Last_Row = ActiveWorkbook.Sheets("report").Range("f" & Rows.Count).End(xlUp).Row
Set sht = ActiveWorkbook.Sheets("Report")
Union(sht.Range("F" & Last_Row), sht.Range("E" & Last_Row), sht.Range("H" & Last_Row)).Copy
End Sub

Regards,
 

Attachments

Last edited by a moderator:
Thanks Narayan,

Narayan actually i am working for automation of my report which includes:
1-open 1st file
2-copy some range
3-open 2nd file
4-paste values of 1st value in 2nd file
3.close 1st file

Honestly i want to become a ninja but still a newbie in vba from past 1 year.
Small things are always pulling my legs. ;);)
Regards,
 
Guarav

The code also runs fine for me in Excel 2010 & 2013

If you are stepping through the code using F8, It will not stop on the Dim line and so the first line will be the File_Name = line
then the Workbooks.open line
 
I am using F8 keys to see step by step action and after opening file it again goes on line2 to :

File_Name = Application.GetOpenFilename(filefilter:="Excel Files (*.xls*), .xls", Title:="Open Weekly Report - Step 1 of 8")

Regards,
 
Y it is happening coz i am a vba newbie and see each & every steps/action
pls suggest what should i do to proceed in my learning towards ninja. ;);)

Regards,
 
Hi Gaurav ,

I am not able to suggest anything much for the code you have posted ; try this and see if the results are different :
Code:
Sub test()
    Dim Last_Row As Double
    Dim File_Name As String
    Dim sht As Worksheet
    Dim Wb As Workbook
    Workbooks.Open Application.GetOpenFilename(filefilter:="Excel Files (*.xls*), .xls", Title:="Open Weekly Report - Step 1 of 8")
    Last_Row = ActiveWorkbook.Sheets("Report").Range("F" & Rows.Count).End(xlUp).Row
    Set sht = ActiveWorkbook.Sheets("Report")
    Union(sht.Range("F" & Last_Row), sht.Range("E" & Last_Row), sht.Range("H" & Last_Row)).Copy
End Sub
The only change is that the 2 statements have been combined in one.

Narayan
 
Thats what it should do
Pressing F8 ignores the Dim statements, it just jumps over them
 
I'd also suggest
Code:
Sub test()
    Dim Last_Row As Double
    Dim File_Name As String
    Dim sht As Worksheet
    Dim Wb As Workbook
    Workbooks.Open Application.GetOpenFilename(filefilter:="Excel Files (*.xls*), .xls", Title:="Open Weekly Report - Step 1 of 8")
    Set sht = ActiveWorkbook.Sheets("Report")
    Last_Row = sht.Range("F" & Rows.Count).End(xlUp).Row
    Union(sht.Range("F" & Last_Row), sht.Range("E" & Last_Row), sht.Range("H" & Last_Row)).Copy
End Sub
 
Back
Top