+ Reply to Thread
Results 1 to 3 of 3

Thread: Format Column Based on Header

  1. #1
    Registered User
    Join Date
    09-21-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    79

    Format Column Based on Header

    Greetings all, trying to write a macro that will format a column based on the header in row 1. In the attached example, the header will include “geo_start_date”, “geo_end_date” and sometimes “wide_release.” These columns need to be formatted as dates (see difference between Start and End worksheets in my example). However, these columns could shift in different reports. For example, “geo_start_date” could be in column E or col F. Basically trying to write an IF statement – something like this:

    IF (cell in row 1) = “geo_start_date” THEN format the entire column as a date (month/day/year format).

    Help is much appreciated, thanks!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-27-2010
    Location
    Berlin, Germany
    MS-Off Ver
    Excel 2002,2007 german
    Posts
    12

    Re: Format Column Based on Header

    try this code

    Public Sub formating()
    Dim i As Integer, j As Long

    For i = 1 To 20
    If ActiveSheet.Cells(1, i).Value = "geo_start_date" Then
    For j = 2 To 1000
    ActiveSheet.Cells(j, i).Value = Format(ActiveSheet.Cells(j, i).Value, "Short Date")
    Next j
    End If
    Next i
    End Sub

  3. #3
    Registered User
    Join Date
    09-21-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2003
    Posts
    79

    Re: Format Column Based on Header

    That works - thanks so much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0