VBA to detect empty cells in range formatted as time values...not?

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
833
Office Version
  1. 365
Platform
  1. Windows
I thought I'd gotten a better understanding of times in VBA and worksheets. Not quite. In VBA trying to test whether a cell is empty. Easy huh? IsEmpty(.Value) or if .value = "" right?

I'm missing SOMETHING. I cannot tell whether a cell that MIGHT be a time is empty. Empty cells keep evaluating to zero which is a time in Excel: Midnight. So my loop looking for specific times in an input range keeps detecting lots of phantom, 12:00 AM values. Of course I have one midnight value to detect so <> 0 does not work. Help me find the light of day here. Thanx In advance.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
you can probably use an if statement that says if isempty(cell.value2)
can you post your VBA code using the code tags & what the value of the cells you're trying to detect/not detect are in your formula bar?

edit: here is info on value2
 
Upvote 0
How about this:
VBA Code:
Sub FindNonTimeCell()
  Dim Cel As Range
  For Each Cel In Selection
    If IsNumeric(Cel) = False Or Cel.Value = 0 Then
      Debug.Print Cel.Address & " Not Time"
    Else
      Debug.Print Cel.Address & " Time"
    End If
  Next Cel
 
End Sub
 
Upvote 0
You know, often help boards help just by forcing one to think more about an issue. I started by testing cell.value <> "". That did not work. So I tried IsEmpty. Dumbass me, looking at my code too much blinded me to the fact that I am using IsEmpty function to test IsEmpty(cell.value). That evaluates to true.

Jeffrey Thanx. Maybe I'm missing something about your nice piece of code but zero is midnight in Excel's time zone. EMPTY cell is not a time, in my case.

Thanks again team MrExcellent.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,008
Members
448,935
Latest member
ijat

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