Excel VBA Paste in Last Row with Data

bored622

New Member
Joined
Mar 2, 2022
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

I'm trying to create a macro that copies cells from A1:C3 in one workbook and pastes them in the last row with the text Period Three in another workbook in column C. Every time a new last row has period 3 that data will only paste in that new last row with Period Three.

This is workbook 1 sheet 1
123
456
789
This is workbook 2 sheet 1
datekeyPeriod One
datekeyPeriod Two
datekeyPeriod Three123456789

Thanks for any help.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hello @bored622, I hope you are well

Try this:

VBA Code:
Sub Paste_in_last_row()
  Dim f As Range
  
  With Workbooks("Workbook 1.xlsx").Sheets(1)
    Set f = Workbooks("Workbook 2.xlsx").Sheets(1).Range("C:C").Find("Period Three", , xlValues, xlWhole, xlByRows, xlPrevious, False)
    If Not f Is Nothing Then
      f.Offset(, 1).Resize(1, 3).Value = .[A1].Resize(1, 3).Value
      f.Offset(, 4).Resize(1, 3).Value = .[A2].Resize(1, 3).Value
      f.Offset(, 7).Resize(1, 3).Value = .[A3].Resize(1, 3).Value
    End If
  End With
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Solution

Forum statistics

Threads
1,215,412
Messages
6,124,761
Members
449,187
Latest member
hermansoa

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