Adjust a range

paulsolar

Well-known Member
Joined
Aug 21, 2013
Messages
689
Office Version
  1. 365
Hi All

I'm having a bad day, been trying to do the below using conditional formatting and cant get it right.

How do I adapt the blow to highlight only columns A-L rather than th whole row?

kind regards

Paul

Code:
Sub color()


  Dim color As Integer


  For Each cell In Sheet2.Range("A2:A65536")


    If IsEmpty(cell) Then GoTo nextcell:
    If Not IsNumeric(cell.Value) Then GoTo nextcell:


    If cell.Value > 0 Then
      color = 37  
    End If  
    cell.EntireRow.Interior.ColorIndex = color
  nextcell:
  Next cell


End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Change this line:
Code:
    cell.EntireRow.Interior.ColorIndex = color
to this:
Code:
    Range(Cells(cell.Row,"A"),Cells(cell.Row,"L")).Interior.ColorIndex = color
 
Upvote 0
Change this:
Code:
cell.EntireRow.Interior.ColorIndex = color

to this:
Code:
Range(cells(cell.Row,1),cells(cell.Row,12)).EntireRow.Interior.ColorIndex = color

There are more efficient ways of doing this though - you should determine the used range rather than running the code for 65,000 rows, and I'd use autofilter and SpecialCells(xlCellTypeVisible) rather than looping through the entire range
 
Upvote 0
Hi Both,

Many thanks for your help, I thought I'd never get home tonight. Been stuck on this for an hour:)
 
Upvote 0

Forum statistics

Threads
1,216,175
Messages
6,129,300
Members
449,499
Latest member
HockeyBoi

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