Finding Two Different Last Lines

mysterious-dr-x

Board Regular
Joined
Jul 29, 2011
Messages
51
So I have a code that is supposed to do the following;
'
' Template: find last line, select range & copy
' Global: open, find 1st blank line, paste, save & close
' Template: select A1
'
Now, everything seems to work fine, except that I need to find the last row of data twice, once in template, & once in global. The 2nd one is the one I have the problem with.

Having defined LR with the following* previously provided to me by JS411 (Thank you.)

Code:
With ws
     LR = .Cells.Find(What:="*", After:=.Range("A1"), _
          LookIn:=xlFormulas, SearchOrder:=xlByRows, _
          SearchDirection:=xlPrevious, MatchCase:=False).Row
      ...
      ...
      ...
End With
My question is; Do I just use the same code to redefine it in the next section, or do I need to use something other than LR & if so, what, how etc?

*Rest of code upon request, but I suspect that you wont be needing it.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I believe you have set ws to be your template workbook. in that case you will need to redifne ws.

on the other hand try using something like this.

Code:
lr =1+ Range("A" & rows.Count).End(xlUp).row
 
Upvote 0
I'll give you more code this time. Now, obviouosly it is still a work in progress, however, what I am still wondering is, can I just ask for LR to be recalculated after I have moved to the other workbook, or do I need to use different letters other than LR or is there some other way to do it entirely???


Code:
    With ws
        LR = .Cells.Find(What:="*", After:=.Range("A1"), _
            LookIn:=xlFormulas, SearchOrder:=xlByRows, _
            SearchDirection:=xlPrevious, MatchCase:=False).Row
            
        Rows("9:" & LR).Select
        Selection.Copy

    End With
    Workbooks.Open Filename:="K:\Testing\Global3.xlsm"
    Sheets("Drawing Register").Select
    
    LR = .Cells.Find(What:="*", After:=.Range("A1"), _
        LookIn:=xlFormulas, SearchOrder:=xlByRows, _
        SearchDirection:=xlPrevious, MatchCase:=False).Row
        
    Range("A" & LR + 1).Select
P.S. ...Bump.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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