Macro to Copy Content

WillPeters

New Member
Joined
Oct 23, 2023
Messages
9
Office Version
  1. 2021
Platform
  1. Windows
Hello all, new to macros here, but this one has me extra stumped.

I want to copy two cells (B21 and B23) in Sheet1 and paste the numbers into Sheet2. The catch is the figures being copied need to be pasted into the last empty column in Rows 2 and 3. The copying and pasting isn't so much an issue, but the last empty column in the row is the tricky part. Anyone able to lend me a hand? Thank you in advance!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try
VBA Code:
Sub MM1()
 Dim lr As Long
 lr = Sheets("Sheet2").Cells(Rows.Count, "B").End(xlUp).Row
 Range("B22:B23").Copy Sheets("Sheet2").Range("B" & lr + 1)
End Sub
 
Upvote 0
VBA Code:
Option Explicit

Sub foo()
    Dim s As Variant
    Dim lc As Long
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Sheets("Sheet1")
    Set ws2 = Sheets("Sheet2")
    lc = ws2.Cells(2, Columns.Count).End(xlToLeft).Column
    Union(ws1.Cells(21, "B"), ws1.Cells(23, "B")).Copy ws2.Cells(2, lc + 1)
    MsgBox "Action Completed"
End Sub
 
Upvote 0
Solution
You are welcome. Thanks for the feedback. You may want to mark it as the solution.
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,398
Members
449,155
Latest member
ravioli44

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