theotherside

New Member
Joined
Jun 9, 2015
Messages
2
The data in my worksheet is being stored in the database as a timestamp even though it's a date. When i pull the data and copy it over i need a quick way to look through multiple sheets for a defined header or column and format it from timestamp to date. the below example does exactly that but only for the first worksheet in the workbook:

Code:
Sub Format_Date_Columns()    
    Dim arr As Variant, ndx As Integer, wkst As Worksheet


    arr = Array("START_DATE", "END_DATE", "DOH")
    
    For ndx = LBound(arr) To UBound(arr)
    
        Set Found = Rows("1:1").Find(arr(ndx), SearchDirection:=xlNext, MatchCase:=False)
        
        If Not Found Is Nothing Then
            Found.EntireColumn.NumberFormat = "mm/dd/yyyy"
        End If
        
    Next ndx
    


End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Probably

Rich (BB code):
Sub Format_Date_Columns()
    Dim arr As Variant, ndx As Integer
    Dim wkst As Worksheet, Found As Range

For Each wkst In ActiveWorkbook.Worksheets
    arr = Array("START_DATE", "END_DATE", "DOH")
    
    For ndx = LBound(arr) To UBound(arr)
    
        Set Found = wkst.Rows("1:1").Find(arr(ndx), SearchDirection:=xlNext, MatchCase:=False)
        
        If Not Found Is Nothing Then
            Found.EntireColumn.NumberFormat = "mm/dd/yyyy"
        End If
        
    Next ndx
    Next


End Sub
 
Upvote 0

Forum statistics

Threads
1,221,709
Messages
6,161,432
Members
451,705
Latest member
Priti_190

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