Paste values in another sheet after last Cell containing Data

rynardc

New Member
Joined
Sep 3, 2024
Messages
10
Office Version
  1. 365
Hi All
I am sure this is not very tricky to do, i have been trying but for the life of me i can`t get it to work. I have 2 sheets, sheet1 contains a simple Data entry form that populates cells D8 and D11, i need these 2 cells copied and then paste special with transpose set to true on Sheet2, also need the data to paste after the last captured data on sheet2 as there will be multiple entries captured on the Data Entry on sheet1
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Managed to get it working, although i don`t think it is an optimal solution it works for now
VBA Code:
Worksheets("Input").Activate
    Range("D8,D11").Select
        Selection.Copy
Worksheets("Scorecards").Activate
    Range("A200").Select
    Selection.End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
 
Upvote 0
You can simplify it a bit by getting rid of most of the Select statements, i.e.
VBA Code:
Worksheets("Input").Activate
Range("D8,D11").Copy
Worksheets("Scorecards").Activate
Range("A200").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True

Note that it is not usually necessary to select ranges in order to work with them. And it actually makes your code run a little slower to have them all in there.
I am guessing that you got that code using the Macro Recorder. The Macro Recorder is very literal, and records every cell selection.
So your recorded code can often be cleaned up a little afterwards to make it shorter and more efficient.
 
Upvote 0
Solution
Thanks Joe4, that does look alot cleaner i will update my code. Yes i use the Macro recorder combined with bits of code i find on google
 
Upvote 0
Thanks Joe4, that does look alot cleaner i will update my code. Yes i use the Macro recorder combined with bits of code i find on google
You are welcome.

Yep, the Macro Recorder is a great tool to get little snippets of code. Just know that you are can often "clean it up a bit", i.e. getting rid of things like "Selects" and "Scrolls".
 
Upvote 0
Great job @Joe4 for the super clean and simplified solution!
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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