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

LVL 1
dabug80Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael FowlerSolutions ConsultantCommented:
Sub mac_1pasteallocation()
    Dim firstEmptyRow as long
    
    firstEmptyRow = Sheets("Data").Range("B" & rows.count).end(xlup).row + 1
    Sheets("Master").Range("B3:B12").Copy
    Sheets("Data").Range("B" & firstEmptyRow).PasteSpecial Paste:=xlPasteAll, Transpose:=True
    Application.CutCopyMode = False
    Sheets("Data").Range("A1").Select

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
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

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
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

dabug80Author Commented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.