Adding current date to next available line in the range

boninm

New Member
Joined
Jan 31, 2025
Messages
9
Office Version
  1. 365
Platform
  1. Windows
hello

I found a code to find the next available row in the range.
Now I want to use the reference it giving me to add the current date
I'm lost on how to do that.
Can anyone help me.

Thank you in advance

How to find the first blank cell in a range in Excel.xlsx
ABCDEFGHIJK
1https://spreadsheetweb.com/find-the-first-blank-cell-in-a-range-in-excel/#
2
3Range = B7:B14
4Position of 1st blank cell3
5Address of 1st blank cell$B$9
6DateFormula above:=CELL("address",INDEX(B7:B14,MATCH(TRUE,ISBLANK(B7:B14),0)))
72025-01-21
82025-01-27
9
10
11
12
13
14
15
16
Sheet1
Cell Formulas
RangeFormula
E4E4=MATCH(TRUE,ISBLANK(B7:B14),0)
E5E5=CELL("address",INDEX(B7:B14,MATCH(TRUE,ISBLANK(B7:B14),0)))
E6E6=FORMULATEXT(E5)
 
Hello,

Do you mean… via VBA ?

Because with formulas you can not write in another cell than the one containing the formula. But with VBA you do not need this formula that you found, you can do it via code.
 
Upvote 0
Hello,

Do you mean… via VBA ?

Because with formulas you can not write in another cell than the one containing the formula. But with VBA you do not need this formula that you found, you can do it via code.
Yes, I would like to do it in the VBA area

The CELL("address",INDEX(B7:B14,MATCH(TRUE,ISBLANK(B7:B14),0))) command tells me where the next available line is, but how to I use that info to write the current date in that cell?
That's what I'm trying to do.

Thanks again
 
Upvote 0
Okay,

So to insert today's date.

Using your formula you can do:

VBA Code:
With Activesheet
  .Range(.Range("E5")).Value = Date
End With

Using a full VBA approach (no need for the formulas):

VBA Code:
With Activesheet
  .Cells(.Rows.Count, "B").End(xlUp).Offset(1, 0).Value = Date
End With

The latter does the same as selecting the last cell in the column B, then pressing CTRL+[↑] (up arrow), and then pressing [↓] once.

This way you get the last used cell in column B, and go down by one to write below it (that's the offset part).
 
Upvote 0
The code did exactly what I ask for .
Now, it needs to add date between row 6 and 13, and not above or below those line

BMO - GIC - 2025-02.xlsm
AB
3Date
4Invested2023-09-21
5Last day of last year2024-12-31
6Saturday2025-02-01
7Saturday2025-02-08
8 
9 
10 
11 
12 
13 
14Ø Ø Ø Ø Ø Insert new lines above this line, not to impact formulas - do not enter value on blue line × × × × ×
Main
Cell Formulas
RangeFormula
A6:A13A6=IF(ISBLANK(B6),"",TEXT(B6,"[$-1009]DDDD"))
 
Upvote 0
Using the first proposition, because with your presentation the second one will not work, you can do like so
VBA Code:
With Activesheet.Range("E5")
  If Range(.Value).Row > 5 And Range(.Value).Row < 14 Then
    .Range(.Value).Value = Date
  End If
End With

If you have follow-up questions like this, just post them at the beginning with the file structure as you just did. They can both completely change the approach to the problem.
 
Upvote 0
OK, tried, and getting run-time error 1004, method range of object _global failed

Also, you got E5, but I think it should be B5
 
Upvote 0
Hello,
As i wrote i was referring to the solution with the cell address calculated via formula. In your fist example the cell address was in E5. The second code can not work since blue line will stop it too early.

So here is the code maybe more clear, and corrected for the error (i wrote Range.Range i think that's why)
VBA Code:
Dim emptyCellAdr As String
emptyCellAdr = Activesheet.Range("E5").Value
With Activesheet
  If .Range(emptyCellAdr).Row > 5 And .Range(emptyCellAdr).Row < 14 Then
    .Range(emptyCellAdr).Value = Date
  End If
End With
 
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,918
Members
453,766
Latest member
Gskier

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