VBA Simple If

Mike54

Active Member
Joined
Apr 17, 2002
Messages
258
Need a bit of help here if possible I am new to VBA. I have been searching the "Excel Questions" but can't seem to find any clues. All this is supposed to do is to select a cell and if empty paste in the date/time but I keep geting Compile error where am I going wrong. Many thanks Mike54.


Private Sub CommandButton1_Click()
Dim X As Integer
Dim Y As Integer
X = 2
Y = 2
Cells(X, Y).Select
If Cells.Value = "" Then Cells(X, Y).Value = Now() Else: X = X + 1

End If
End Sub
 
Hello Peter sorry for the late reply **** meetings etc. Many thanks for taking the time and trouble to help me, I'm not quite sure why but your answer came out like this....

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN>

Range("A65536").End(xlUp).Offset(1, 0).Value = Now()

Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

However I managed to take out the HTML type stuff and was left with just a line of code which works perfectly cheers it looks so simple and elegant, not that i understand VBA ranges but I'll keep working. Mike54
 
Upvote 0
Hello Peter sorry for the late reply **** meetings etc. Many thanks for taking the time and trouble to help me, I'm not quite sure why but your answer came out like this....

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN>

Range("A65536").End(xlUp).Offset(1, 0).Value = Now()

Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

However I managed to take out the HTML type stuff and was left with just a line of code which works perfectly cheers it looks so simple and elegant, not that i understand VBA ranges but I'll keep working. Mike54
 
Upvote 0
Hello Peter sorry for the late reply **** meetings etc. Many thanks for taking the time and trouble to help me, I'm not quite sure why but your answer came out like this....

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN>

Range("A65536").End(xlUp).Offset(1, 0).Value = Now()

Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

However I managed to take out the HTML type stuff and was left with just a line of code which works perfectly cheers it looks so simple and elegant, not that i understand VBA ranges but I'll keep working. Mike54
 
Upvote 0
Hello Peter sorry for the late reply **** meetings etc. Many thanks for taking the time and trouble to help me, I'm not quite sure why but your answer came out like this....

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()
Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
Application.EnableEvents = <SPAN style="color:#00007F">False</SPAN>

Range("A65536").End(xlUp).Offset(1, 0).Value = Now()

Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
Application.EnableEvents = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

However I managed to take out the HTML type stuff and was left with just a line of code which works perfectly cheers it looks so simple and elegant, not that i understand VBA ranges but I'll keep working. Mike54
 
Upvote 0

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