Find first cell then fill the cells until last used row

urobee

Board Regular
Joined
Jan 30, 2015
Messages
98
Hy,


My target is to fill the cells in column B with a formula from the first empty cell for the last used row.

I can fill the cells from a given cell until last used row with this code:

Code:
Dim Lastrow As Long
Lastrow = .Range("A" & Rows.Count).End(xlUp).Row
With shBom
'other parts of the macro
	.Range("C2:C" & Lastrow).FillDown
End With

And I can find the firts empty cell in a row:

Code:
Dim Firstrow As Range
Set Firstrow = shMySheet.Range("B1").End(xlDown).Offset(1, 0)
'other parts of the macro

But how can I combine this two?
(the first and a last used cell is change often so it's not acceptable to set a constant cell address in the code)

Thanks!
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
3,050
Office Version
  1. 2016
Platform
  1. Windows
Code:
Dim bRng As Range
Set bRng = Range(Firstrow, Cells(Lastrow, "B"))
 

urobee

Board Regular
Joined
Jan 30, 2015
Messages
98
Thanks,

I needed to modify your code but it is good for a start!
 

Watch MrExcel Video

Forum statistics

Threads
1,109,360
Messages
5,528,236
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top