Link to home
Start Free TrialLog in
Avatar of dabug80
dabug80

asked on

Excel Macro Edit (find last blank row)

Hi,

I have the following macro code below. It currently copies data from the master sheet and transposes it to the data sheet to B2. I would like the macro code edited so it paste/transposes the copied data to the last blank row of the data sheet - after row 1. Is this possible?

Thanks

Sub mac_1pasteallocation()


    Sheets("Master").Select
    Range("B3:B12").Copy
    
    Sheets("Data").Select
    Range("B2").PasteSpecial Paste:=xlPasteAll, Transpose:=True
    Application.CutCopyMode = False
    Range("A1").Select


End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Subodh Tiwari (Neeraj)
Try this.....

Sub mac_1pasteallocation()

    Sheets("Master").Range("B3:B12").Copy
    Sheets("Data").Select
    Range("B" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteAll, Transpose:=True
    Application.CutCopyMode = False
    Range("A1").Select

End Sub

Open in new window

try:

Sub mac_1pasteallocation()


    Sheets("Master").Select
    Range("B3:B12").Copy
   
    Sheets("Data").Select
    lastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "B").End(xlUp).Row
   
    Range("B" & lastRow + 1).PasteSpecial Paste:=xlPasteAll, Transpose:=True
    Application.CutCopyMode = False
    Range("A1").Select


End Sub
While copying the data from Master sheet, you don't need to select the Master sheet necessarily. You just need to qualify the range which is being copied with the sheet reference and it will copy the range from that sheet no matter which sheet is currently active.

Therefore just the following line would be sufficient...
Sheets("Master").Range("B3:B12").Copy

Open in new window

Avatar of dabug80
dabug80

ASKER

Thanks