Find last row and insert data

db2020

New Member
Joined
Jun 6, 2021
Messages
21
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi,

I want to insert text (e.g. "Text2") below the last cell with text in column A, and the number of rows in which I have to insert this text should be equal to the rows in column B.

See example below, in the 3 empty cells of column A I want to insert the text "Text2":

A B
Text Data
Text Data
Text Data
Text Data
Text Data
...... Data
...... Data
...... Data

How do I do this?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Where exactly is the text that you want to input come from?
 
Upvote 0
It's not in the file so that has to be added to the macro
 
Upvote 0
Is it hard-coded (the same thing every time)?
Or do you want the VBA code to prompt the user for the text at run-time?
 
Upvote 0
OK, try something like this:
VBA Code:
Sub MyFill()

    Dim tx As String
    Dim lrB As Long
    Dim frA As Long
    
'   Enter hard-coded text
    tx = "Some text here"
    
'   Find last row in column B with data
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Find first row in column A needing data
    frA = Cells(Rows.Count, "A").End(xlUp).Row + 1
    
'   Fill blank columns in column A
    If lrB > frA Then Range(Cells(frA, "A"), Cells(lrB, "A")).Value = tx
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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