Help selecting cells

andyreloaded

Board Regular
Joined
Aug 1, 2006
Messages
80
I need to select all cells that are formatted as date, if that's possible. Like if there was a Go To -> Special -> Cell Format = Date... Any ideas? I want to select the cells regardless of any other characteristic, including whether there are values or the cell is empty.

Also, as a side note, do you know what governs the default cell formatting of new sheets created within a workbook? I create a sheet, and all cells default to format = date.

Thanks,
Andy
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Here is a macro that should select all the cells in your selection that are formatted as dates. If your date format is something other than "m/d/yyyy", then change that line in the macro to match the date format that is being used in your spreadsheet.

Code:
Sub SelectDateFormats()
'This macro will select all the items in the selection that are
'formatted as dates

Dim rngCell As Range, rngRangeToCheck As Range
Dim strAddressString As String

'Set the range to check, limited to both the selection and the used range
Set rngRangeToCheck = Intersect(ActiveSheet.UsedRange, Selection)

For Each rngCell In rngRangeToCheck
    'Check to see if the cell is formatted as a date
    'If so, add the address to the address string, which will be
    'selected at the end of the macro
    'Add commas between cell addresses
    If rngCell.NumberFormat = "m/d/yyyy" Then
        strAddressString = strAddressString & "," & rngCell.Address
    End If
Next rngCell

'Select the cells with date formats, if there are any
If Len(strAddressString) > 0 Then
    'The first entry will be preceded with a comma, so strip that off
    strAddressString = Right(strAddressString, Len(strAddressString) - 1)
    Range(strAddressString).Select
End If

End Sub

As for why your new workbooks or worksheets are automatically formatted as dates, my guess would be that one of the default templates (Book.xlt or Sheet.xlt) has date formatting everywhere. Another possibility might be that the default Style has numbers formatted as dates.
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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