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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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
Record a macro of you entering some text into the text box.
What code does the macro recorder give you?
 
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 :eek:
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,709
Members
449,464
Latest member
againofsoul

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