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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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