Consulting

Results 1 to 3 of 3

Thread: Solved: Need Macro to Replace ## with the Column Heading Name

  1. #1

    Solved: Need Macro to Replace ## with the Column Heading Name

    Hi Guys,

    Please check the excel sheet, I need a macro to work. where "##" should be replaces with the Column Heading in this case Heading is "RochesterNY" without last two letters i.e. "Rochester", where # should be replaces with the whole Column Heading i.e "RochesterNY".
    Here is the file link:

    HTML Code:
    http://www.4shared.com/file/BNHtxzak/Lawyers_data_base.html
    Any help?


    I have nearly 120 Columns. Its very hard to find and replace.


    Waiting for your kind reply.

    Thanks,
    Last edited by krishhi; 09-20-2011 at 05:05 AM.
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You can attach files here.

    [VBA]Sub ChangeNums()
    Dim col As Range, cell As Range
    For Each col In ActiveSheet.UsedRange.Columns
    For Each cell In col.Cells
    If cell.Address <> col.Cells(1, 1).Address Then
    cell.Value = Replace(cell.Value, "##", Left(col.Cells(1, 1).Value, Len(col.Cells(1, 1).Value) - 2))
    cell.Value = Replace(cell.Value, "#", col.Cells(1, 1).Value)
    End If
    Next cell
    Next col
    ActiveSheet.UsedRange.Columns.AutoFit
    End Sub
    [/VBA]

  3. #3
    Quote Originally Posted by Kenneth Hobs
    You can attach files here.

    [vba]Sub ChangeNums()
    Dim col As Range, cell As Range
    For Each col In ActiveSheet.UsedRange.Columns
    For Each cell In col.Cells
    If cell.Address <> col.Cells(1, 1).Address Then
    cell.Value = Replace(cell.Value, "##", Left(col.Cells(1, 1).Value, Len(col.Cells(1, 1).Value) - 2))
    cell.Value = Replace(cell.Value, "#", col.Cells(1, 1).Value)
    End If
    Next cell
    Next col
    ActiveSheet.UsedRange.Columns.AutoFit
    End Sub
    [/vba]
    Millions of Thanks. You just made my day very beautiful.

    Thank you once again.
    Happiness keeps u sweet, trials keep u strong, sorrow keeps u human, failure keeps u humble, success keeps u glowing, but only God keeps u going

Posting Permissions

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