VBA to add text next to pasted data then add new text just below that data

excelnewb22

New Member
Joined
Nov 10, 2022
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
Hi all,

I'm looking to find a Macro that will look at a list of data in Column A, and add text from the last used cell in column B down to the same row as the last cell used in column A. Sell below: (Data is cells already used, HERE is where the macro would need to put the information.

Data Data
Data Data
Data Data
Data HERE
Data HERE
Data HERE
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Maybe
VBA Code:
Dim lngLastA As Long, lngLastB As Long

lngLastA = Cells(Rows.count, "A").End(xlUp).Row
lngLastB = Cells(Rows.count, "B").End(xlUp).Row
Range("B" & lngLastB).Copy Range("B" & lngLastB + 1, "B" & lngLastA)
No idea what event you want to use to trigger it so I left that off. You might want to disable other events from firing when the code makes changes.
 
Upvote 0
Hi Micron - Thanks so much for that!

How can I edit the code so that rather than copying text, it's adding it?

Data Data
Data Data
Data Data
Data
Data
Data

So it would look at column B like above and work out how many cells it needs to fill compared to the remainder of the list in column A?

For example adding the word "text" to where the gaps are in Column B above?
 
Upvote 0
I think I figured it out based on your code and now works a treat:

VBA Code:
Sub AddText1()

Dim lngLastA As Long, lngLastB As Long

lngLastA = Cells(Rows.Count, "A").End(xlUp).Row
lngLastB = Cells(Rows.Count, "B").End(xlUp).Row
Range("B" & lngLastB + 1, "B" & lngLastA) = "Blue"

End Sub

Thank you Micron!
 
Last edited by a moderator:
Upvote 0
Solution
and add text from the last used cell in column B
Don't you have to copy what's in the last used cell in column B in order to paste it anywhere? I see you are inserting the word Blue, not necessarily the text in the last cell. Oh well, glad you figured it out. Maybe you could mark this thread as solved so as to get it off the unsolved list?
Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

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