Run a macro for a specific range

neholsti

New Member
Joined
Mar 10, 2011
Messages
10
I have a macro set up to add a specific number for each fill color of a cell, the problem is I dont want it to do it for the entire spreadsheet just a range of cells (A4 - T59). Can anyone help me? Ive included the code below

Option Explicit
Sub NumberColorValue()
Dim R As Range
With ActiveSheet
For Each R In ActiveSheet.UsedRange
Select Case R.Interior.ColorIndex
Case 1
R.Interior.ColorIndex = 1
R.Value = 1
Case 2
R.Interior.ColorIndex = 2
R.Value = 2
Case 3
R.Interior.ColorIndex = 3
R.Value = 1
Case 4
R.Interior.ColorIndex = 4
R.Value = 4
Case 5
R.Interior.ColorIndex = 5
R.Value = 5
Case 6
R.Interior.ColorIndex = 6
R.Value = 3
End Select
Next R
End With
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,155
Can I ask why this:

Case 1
R.Interior.ColorIndex = 1
R.Value = 1

Just a suggestion, but why not just check ea cell and if NOT .ColorIndex = xlColorIndexNone, then cell.Value = .colorindex
 
Upvote 0

Forum statistics

Threads
1,191,043
Messages
5,984,302
Members
439,882
Latest member
gerdc

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
Top