+ Reply to Thread
Results 1 to 3 of 3

Macro

  1. #1
    mast
    Guest

    Macro

    I have a macro to change the colour of a column depending on the contents of
    one of the cells in that column.
    Sub Column_Colour()
    ActiveCell.Select
    If ActiveCell = "Allocated" Then
    Range("H1:H100").Interior.ColorIndex = 36
    ElseIf ActiveCell = "In Use" Then
    Range("H1:H100").Interior.ColorIndex = 37
    ElseIf ActiveCell = "Returned" Then
    Range("H1:H100").Interior.ColorIndex = 43
    End If
    ActiveSheet.Range("A5").Activate

    End Sub

    As you can see this is specific only to column "H". How can I change this
    macro to be available to any column that is selected?

  2. #2
    cmart02
    Guest

    RE: Macro

    You can try something like:

    Sub Column_Colour()
    col = Mid(CStr(ActiveCell.Address), 2, 1)

    If ActiveCell = "Allocated" Then

    Range(col & "1:" & col & "100").Interior.ColorIndex = 36
    ElseIf ActiveCell = "In Use" Then
    Range(col & "1:" & col & "100").Interior.ColorIndex = 37
    ElseIf ActiveCell = "Returned" Then
    Range(col & "1:" & col & "100").Interior.ColorIndex = 43
    End If
    ActiveSheet.Range("A5").Activate

    End Sub


    Regards,
    Robert

  3. #3
    mast
    Guest

    RE: Macro

    Works exactly as I want. Many thanks

    "cmart02" wrote:

    > You can try something like:
    >
    > Sub Column_Colour()
    > col = Mid(CStr(ActiveCell.Address), 2, 1)
    >
    > If ActiveCell = "Allocated" Then
    >
    > Range(col & "1:" & col & "100").Interior.ColorIndex = 36
    > ElseIf ActiveCell = "In Use" Then
    > Range(col & "1:" & col & "100").Interior.ColorIndex = 37
    > ElseIf ActiveCell = "Returned" Then
    > Range(col & "1:" & col & "100").Interior.ColorIndex = 43
    > End If
    > ActiveSheet.Range("A5").Activate
    >
    > End Sub
    >
    >
    > Regards,
    > Robert


+ 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.6.0 RC 1