sorry for such a remedial question, but im thoroughly stumped

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
458
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I want to have the formatting (green highlighted rolls and bold font) STOP when it reaches the last column that has any formatting (using columncount) instead of having the green highlight continue on out past the last column. But I cant figure out what VBA to use to accomplish this. When I use the (Cell.Row) (which i circled in green in the code I posted below) it obviously will format the ENTIRE row... what do I need to change so that it stops the formatting on the last column that contains any text/formating?

14j0m02.jpg



This is what it looks like now, but I need to green formatting to stop once it reaches the column with the last name in row A (Zuri,Snow)

25zgf1u.jpg
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try:
Code:
If Cell Like "*PO*" Then
    With Range(Cells(Cell.Row, 1), Cells(Cell.Row, mCol))
        .Interior.Color = 65280
        .Font.Bold = True
        .Borders.Weight = xlMedium
    End With
End If
 
Upvote 0
Can you post your code directly in the thread please (then select the code and click the # icon so it puts it in code tags) so that it can be copied rather then as an image that can't be copied?

Edit: see mumps post as should work for you so I shouldn't need to post a suggestion but in future please post your code directly in the thread.
 
Last edited:
Upvote 0
Maybe
Code:
Cell.Resize(, mcol).Interior.Color = 65280
In future, please post your code here (using code tags), rather than just showing an image.
 
Upvote 0
Maybe
Code:
Cell.Resize(, mcol).Interior.Color = 65280
In future, please post your code here (using code tags), rather than just showing an image.

Will do. I dont post here too often, so sorry about that.
 
Upvote 0
Thank you, that worked great.

Here is my new code, but I am having trouble finding where to insert a 'else' command so that the rows that do NOT contain the text its looking for (in this case the "*Pr*) they can be formatted differently than the others (want them to have a lighter font lighter and the rows narrower.) Where and how can i make use of the else command to do this? (or is that not correct and I should be doing it a different way?)

Thanks again

Code:
Dim mCol As Long
    mCol = ActiveSheet.UsedRange.Columns.Count
    nCol = ActiveSheet.UsedRange.Rows.Count
    For Each Cell In Range(Cells(6, 1), Cells(nCol, 1))
    
If Cell Like "*Pr*" Then
    With Range(Cells(Cell.Row, 1), Cells(Cell.Row, mCol))
        .Interior.Color = 65280
        .Font.Bold = True
        .Borders.Weight = xlMedium
    
    End With
    
End If


Next
 
Upvote 0
Something like the below (change the formatting to suit)?

Code:
    Dim mCol As Long, nCol As Long, Cell As Range
    mCol = ActiveSheet.UsedRange.Columns.Count
    nCol = ActiveSheet.UsedRange.Rows.Count

    For Each Cell In Range(Cells(6, 1), Cells(nCol, 1))
        With Range(Cells(Cell.Row, 1), Cells(Cell.Row, mCol))

            If Cell Like "*Pr*" Then
                .Interior.Color = 65280
                .Font.Bold = True
                .Borders.Weight = xlMedium
            Else
                .Font.Color = 10213316
                Rows(Cell.Row).RowHeight = 28.5

            End If

        End With

    Next
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,962
Members
449,200
Latest member
indiansth

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