Very Simple Macro I can't get to work

jeffmoseler

Well-known Member
Joined
Jul 16, 2004
Messages
540
Here is the macro. I used to know how to do this kind of thing very easily, but it has been a while. It doesn't give any errors, it just won't delete the contents if the value is FALSE.

Dim dte As Date
dte = Date

If Range("I10") = "TRUE" Then
Range("E10").ClearContents
Else
Range("E10") = dte
End If
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
The way that code is written, it looks like you want to clear it if is TRUE, not FALSE, take TRUE out of quotes, unless your spreadsheet actually contains a text TRUE, not the value TRUE.

Code:
Sub test()
Dim dte As Date
dte = Date

If Range("I10") = True Then
Range("E10").ClearContents
Else
Range("E10") = dte
End If
End Sub

or you can take that part out:

Code:
Sub test()
Dim dte As Date
dte = Date

If Range("I10") Then
Range("E10").ClearContents
Else
Range("E10") = dte
End If
End Sub
 
Upvote 0
That worked fine, but I thought of somthing else. What if I wanted to use the checkbox itslef to determine the True/False value. Like this

Dim dte As Date
dte = Date
Range("I10").Select
If ("Check Box 2") = True Then
Range("E10") = dte
Else
Range("E10").ClearContents
End If
 
Upvote 0

Forum statistics

Threads
1,213,539
Messages
6,114,221
Members
448,554
Latest member
Gleisner2

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