Conditional formatting of a group of text boxes.

smar2832

New Member
Joined
Oct 13, 2011
Messages
17
Hi,

I am using around 200 individual text boxes in a single worksheet that each contain a formula pointing to the value of a unique cell in another worksheet in the same workbook. Each cell being referenced contains a numeric value. I wish to apply conditional formatting to the value in the textbox such that:

If the cell value > 0, use black text.
If the cell value <= 0 use green text.

I have attempted to modify vba code I have found on similar topics without success.

Is anyone able to help ?
 

smar2832

New Member
Joined
Oct 13, 2011
Messages
17
Sorry, I probably should have provided that before.

I am using this code:

Dim shp As Shape, tmp


For Each shp In ActiveSheet.Shapes
'only operate on linked shapes
If Len(shp.DrawingObject.Formula) > 0 Then
tmp = shp.TextFrame.Characters.Text
'ignore non-numeric values
If IsNumeric(tmp) And Len(tmp) > 0 Then
shp.TextFrame.Characters.Font.Color = _
IIf(tmp >= 0, vbGreen, vbRed)
End If
End If
Next shp


And I am receiving the following error message:

Run-time error `438':

object doesn't support this property or method.

I have inserted the textboxes using the Textbox icon under the Insert tab in the ribbon.
 
Last edited:

smar2832

New Member
Joined
Oct 13, 2011
Messages
17
this one: If Len(shp.DrawingObject.Formula) > 0 Then

I have tested it on a simple spreadsheet and it works until there are certain types shapes present. i.e. other than text boxes! like a line (i have drawings on this spreadsheet as well)

I am pretty sure the non-textbox shapes are causing the error!
 

Forum statistics

Threads
1,081,556
Messages
5,359,555
Members
400,533
Latest member
fpenning

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top