Last row VBA help

EXCELGPS

New Member
Joined
Aug 31, 2017
Messages
13
Hi,
I'm after a bit of help please, I wrote this code some 17 years ago and it works fine until now as column D no has formulas in so it is not going to the last row with data in it as I assume it doesn't think the cell is empty because of the formula.
Any way around this please?

The bit causing the problem is highlighted red.

Rich (BB code):
Case Else
    With WS
    
    
         myRow = wsQuote.Range("B65536").End(xlUp).Row
         .Range("J7:K7").Copy
         
        wsQuote.Cells(myRow + 4, 1).PasteSpecial Paste:=xlValues
        wsQuote.Cells(myRow + 4, 1).PasteSpecial Paste:=xlFormats
         
        myRow = wsQuote.Range("B65536").End(xlUp).Row
        .Range("J9:K35").Copy
         
        wsQuote.Cells(myRow + 2, 1).PasteSpecial Paste:=xlValues
        wsQuote.Cells(myRow + 2, 1).PasteSpecial Paste:=xlFormats
         
        myRow = wsQuote.Range("B65536").End(xlUp).Row
         
        LastRow = WS.Range("D65536").End(xlUp).Row
        .Range("B40:D" & LastRow).Copy
         
        wsQuote.Cells(myRow + 2, 1).PasteSpecial Paste:=xlValues
        wsQuote.Cells(myRow + 2, 1).PasteSpecial Paste:=xlFormats
        
        'Set print areas
        LastRow = WS.Range("D65536").End(xlUp).Row
        
        '.Range("B1:H" & LastRow).Select
        
       .PageSetup.PrintArea = "B1:H" & LastRow + 6
         
    End With
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Welcome to the forums!

Try:

Code:
LastRow = ws.Range("D:D").Find(What:="*", _
                        Lookat:=xlPart, _
                        LookIn:=xlValues, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlPrevious, _
                        MatchCase:=False).Row
 
Upvote 0
Amend it to
Code:
LastRow = WS.Range("D" & Rows.Count).End(xlUp).Row
.Range("B40:D" & LastRow).Copy
 
Upvote 0
Try changing D to another column that will show the last row of data ie
Code:
LastRow = WS.Range("[COLOR=#ff0000]B[/COLOR]" & Rows.Count).End(xlUp).Row
 
Upvote 0
Works perfect, thanks for your help.

Welcome to the forums!

Try:

Code:
LastRow = ws.Range("D:D").Find(What:="*", _
                        Lookat:=xlPart, _
                        LookIn:=xlValues, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlPrevious, _
                        MatchCase:=False).Row
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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