Changing cell color randomly for counter increment through VBA Loop

ChauhanSaab

New Member
Joined
May 5, 2020
Messages
3
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi,

For the below goal seek macro, the counter cell AF1 changes on every iteration.
Can i add some code to change the color of the cell randomly on every counter increment till the loop completes.

Sub Goal_Seek_Range()
Dim j As Integer
Dim count As Long
count = 0

For j = 5 To 2482
Cells(j, "AH").GoalSeek Goal:=135, ChangingCell:=Cells(j, "AG")
count = count + 1
Range("AF1").Value = count
DoEvents

Next j
ActiveWorkbook.Save
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi & welcome to MrExcel.
How long does it take to run that code?
 
Upvote 0
It takes around 2 hours since the base file contains many formulas that gets dynamically updated.
Mostly I run this macro before going to bed and by morning the run gets completed.
 
Upvote 0
Ok, you could use
VBA Code:
Range("AF1").Value = count
Range("AF1").Interior.Color = j * 10000
DoEvents
But change j from Integer to Long
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,220
Members
448,876
Latest member
Solitario

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