VBA TRUE/FALSE help

hissonrr

Board Regular
Joined
Feb 6, 2016
Messages
106
I am using a Macro I pulled offline to timestamp certain cells when changed

Is there a way to alter this macro so that it works if instead of looking for any value and blank values, it will add a date/time if TRUE is inputted in O11 and clears it if O11 is FALSE?

Any help would be appreciated as I am a VBA novice.

-R


Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)        With Target
            If .Count > 1 Then Exit Sub
            If Not Intersect(Range("O11"), .Cells) Is Nothing Then
                Application.EnableEvents = False
                If IsEmpty(.Value) Then
                    .Offset(0, 1).ClearContents
                Else
                    With .Offset(0, 1)
                        .NumberFormat = "dd mmm yyyy hh:mm:ss"
                        .Value = Now
                    End With
                End If
                Application.EnableEvents = True
            End If
        End With
    End Sub
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,
Try this.
Code:
Sub Worksheet_Change(ByVal Target As Excel.Range)        
With Target
            If .Count > 1 Then Exit Sub
            If Not Intersect(Range("O11"), .Cells) Is Nothing Then
                If Range("O11").value=False then
   
                Application.EnableEvents = False
                    .Offset(0, 1).ClearContents
                Else
                    .Offset(0, 1).NumberFormat = "dd mmm yyyy hh:mm:ss"
                        .Offset(0,1).Value = Now
                End If
                Application.EnableEvents = True
            End If
        End With
    End Sub
 
Upvote 0
Try this:

Code:
With Target
    If .Count > 1 Then Exit Sub
    If Not Intersect(Range("O11"), .Cells) Is Nothing Then
        Application.EnableEvents = False
        Select Case LCase(.Value)
            Case True
                With .Offset(0, 1)
                    .NumberFormat = "dd mmm yyyy hh:mm:ss"
                    .Value = Now
                End With
            Case False
                .Offset(0, 1).ClearContents
        End Select
        Application.EnableEvents = True
    End If
End With
 
Upvote 0
neither are working

It may be because the cell O11 is linked to a checkbox, so if it is checked it will be TRUE and if not it will be FALSE

-R
 
Upvote 0
Hi,
Check now. It's not because you have the cell linked to the check box.

Code:
Sub Worksheet_Change(ByVal Target As Excel.Range)        
With Target
            If .Count > 1 Then Exit Sub
            If Not Intersect(Range("O11"), .Cells) Is Nothing Then
                If LCase(Range("O11")).value="false" then
   
                Application.EnableEvents = False
                    .Offset(0, 1).ClearContents
                Else
                    .Offset(0, 1).NumberFormat = "dd mmm yyyy hh:mm:ss"
                        .Offset(0,1).Value = Now
                End If
                Application.EnableEvents = True
            End If
        End With
End Sub
 
Upvote 0
Nope

still is blank when I check/uncheck the checkbox that makes O11 TRUE/FALSE


using the first one you posted If I change the O11 to a actual number it works
 
Upvote 0
Assuming its a form checkbox then place this in a standard module:

Code:
Sub CheckBoxO11()

With Range("O11")
    Select Case LCase(.Value)
        Case true
            With .Offset(0, 1)
                .NumberFormat = "dd mmm yyyy hh:mm:ss"
                .Value = Now
            End With
        Case false
            .Offset(0, 1).ClearContents
    End Select
End With

End Sub

Then right click on the checkbox and assign the macro to the checkbox.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,748
Messages
6,180,721
Members
452,995
Latest member
isldboy

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