For.... Next Loop? Best way forward?

smar2832

New Member
Joined
Oct 13, 2011
Messages
17
Hi VBAers,

As I delve deeper into excel I am learning many more exciting functions but am also coming up against many more problems!


Is there a way to use a "for...next" loop in order to copy the below code 300 times? i.e. I have 300 different text boxes that are conditionally formatted individually based on 300 different cells. If i have a list of the textboxes and a list of the cells could i use a loop to make this happen? or am i best to copy the code 300 times and manually update it?

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Sheets("Aust Fixed").Range("B272") > 0 Then
Sheets("Australia").Shapes("TextBox 406").Select
With Selection.Font
.Color = RGB(0, 0, 0)
End With

ElseIf Sheets("Aust Fixed").Range("B272") < 0 Then

Sheets("Australia").Shapes("TextBox 406").Select

With Selection.Font
.Color = RGB(255, 0, 0)
End With

End If

End Sub

Any help would be much appreciated!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I'm guessing then that its an ActiveX textbox. My Mac doesn't support ActiveX, so you should look through the Object Browser and find the path of properties of an ActiveX text box that lead to .Font.Color
 
Upvote 0
No its not activex.... its just a textbox from the insert tab...... I think the activex ones dont have any spaces i.e.: textbox1


have you got it working on your mac? would it be possible to post a working example?

thanks heaps BTW

p.s. <code>'With Sheets("Aust Fixed").Range("B259")
'ActiveSheet.Shapes("TextBox 664").TextFrame.Characters.Font.Color = RGB(IIf(.Value < 0, 255, 0), 0, 0)
'End With
</code>

works fine. just need to loop....
 
Last edited:
Upvote 0
weird. Just tried. The Macro does not record anything related to creating a textbox, writing in a textbox, or changing the font of the textbox. the only thing it recorded was me click a cell out of it to deselect it :eeek:
 
Upvote 0

Forum statistics

Threads
1,224,889
Messages
6,181,611
Members
453,056
Latest member
apmale77

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