How to add today's date if cell is empty, and if not skip to next column?

Hifty

New Member
Joined
Jun 8, 2021
Messages
10
Office Version
  1. 365
Im a complete VBA noob and im trying to do what seems to be a simple thing.

The purpose of my code is to make a button where it checks to see if the cell is not empty, it should offset to the next column and if it is empty, then it should add todays date.
So each day I press the button it adds a new date next to the old one.

Here is the code I wrote:

Private Sub New_Date_Click()
ActiveSheet.Range("E1").Select
If Not IsEmpty(ActiveCell.Value) Then
ActiveCell.Offset(0,1)
Else
ActiveCell.Value = Date
End Sub

It gives me an error message that an Equal sign is missing on row 4 where the offset is.

The images show what im trying to do.
 

Attachments

  • Help 1.PNG
    Help 1.PNG
    37.6 KB · Views: 50
  • Help 2.PNG
    Help 2.PNG
    24 KB · Views: 48

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
What do you wan to do if E1 is not empty?
 
Upvote 0
What do you wan to do if E1 is not empty?
If E1 is not empty, I want it to check if the cell on its right is empty, so F1. And if F1 is not empty, I want it to check the next one, and so on.
 
Upvote 0
Ok, how about
VBA Code:
Sub New_Date_Click()
   Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Value = Date
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub New_Date_Click()
   Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Value = Date
End Sub
Wow I was really overthinking it, didnt know some of these functions existed, thanks a bunch!
I'll keep learning VBA!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
There is no such thing as Row A, there is column A & row 1.
 
Upvote 0
my apologies for not clarifying, I mean instead of print the date on A1 then B1 Then C1 then D1 to be A1 , A2, A3 since the date start from Column A and moving down
 
Upvote 0
In that case you can use
Excel Formula:
   Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Date
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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