+ Reply to Thread
Results 1 to 4 of 4

Need help for macro to conditionally format a selected range

  1. #1
    Registered User
    Join Date
    10-30-2014
    Location
    Westerville, OH
    MS-Off Ver
    Excel 2007
    Posts
    12

    Need help for macro to conditionally format a selected range

    Hi All,

    I have data as below:
    COL1 COL2 COL3 COL4 COL5 COL6 COL7 COL8
    A A A A A A A 1
    A A A A A A A 1
    A A A A A A A 1
    A A A A A A A 1
    A A A A A A A 2
    A A A A A A A 2


    what I need to do is if col8 = 1, then format the range col3 through col7 (lets say make font.name = "Arial") and if col8 = 2, then format col1 through col2. Can somebody please help me create a Macro for this requirement.

    Excel 2007

    Thanks

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Need help for macro to conditionally format a selected range

    Hi,

    You don't of course NEED a macro for this. A simple conditional format will do.

    In G2 create two new rules by entering the following conditional formats using the 'Use a formula...option

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    set the appropriate formats, font,colour etc.
    then in the CF Wizard set the 'Applies to' range to C2:C100

    add a second rule
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    set the format for this and apply it to A1:B100
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    10-30-2014
    Location
    Westerville, OH
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Need help for macro to conditionally format a selected range

    Thanks Richard, But with conditional formatting, I cannot change the font, all I can change is font style, color and underline stuffs only.

  4. #4
    Registered User
    Join Date
    10-30-2014
    Location
    Westerville, OH
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Need help for macro to conditionally format a selected range

    Thanks Richard. I did it anyway with a Macro.

    Sub format_it()
    Dim rownm As Integer, colmn As Integer, i As Integer, j As Integer
    rownm = 100
    colnm = 7
    For i = 2 To rownm
    If Cells(i, 8).Value = 1 Then
    For j = 3 To colnm
    Cells(i, j).Interior.Color = vbYellow
    Cells(i, j).Font.Name = "Arial"
    Cells(i, j).Font.Size = "8"
    Cells(i, j).Borders(xlEdgeBottom).LineStyle = xlContinuous
    Cells(i, j).Borders(xlEdgeBottom).Weight = xlMedium
    Next j
    End If

    If Cells(i, 8).Value = 2 Then
    For j = 1 To 2
    Cells(i, j).Interior.Color = vbYellow
    Cells(i, j).Font.Name = "Arial"
    Cells(i, j).Font.Size = "8"
    Cells(i, j).Borders(xlEdgeBottom).LineStyle = xlContinuous
    Cells(i, j).Borders(xlEdgeBottom).Weight = xlMedium
    Next j
    End If

    Next i

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Conditionally Format Dynamic Range
    By hamidxa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2014, 12:43 PM
  2. Need help looping through multiple sheets to conditionally format the same range/sheet
    By xcelnovice101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2014, 10:54 AM
  3. Best Way to Conditionally Format Range (Multiple Columns and Rows)?
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-14-2013, 04:53 PM
  4. Replies: 4
    Last Post: 06-04-2012, 12:08 PM
  5. [SOLVED] Vba code to conditionally format a specific range
    By kelwood in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-29-2012, 10:14 AM

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