TextBox backcolor

saint1415

New Member
Joined
Jan 22, 2019
Messages
3
So I have a Geographic Heat Map with Textboxes for all 50 states and 1 for DC. I need to see about adding to the following code to make the Textbox backcolor/fillcolor equal the state color.

Sub Paint()
Dim i As Integer
For i = 1 To 50
'First, paint the state shapes
Range("actorder").Value = i
ActiveSheet.Shapes(Range("actstate").Value).Fill.ForeColor.RGB = _
Range(Range("actcolorcode").Value).Interior.Color


ActiveSheet.Shapes(Range("acttext").Value).Select
With Selection
'Second, update the text boxes
.Text = Range("acttextvalue").Value

'(Optional) Format the text boxes
.ShapeRange.Fill.ForeColor.RGB = RGB(0, 0, 0)
.ShapeRange.Fill.Transparency = 1
.ShapeRange.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
.ShapeRange.TextFrame2.TextRange.Font.Shadow.Visible = False
.ShapeRange.TextFrame2.MarginLeft = 2.5
.ShapeRange.TextFrame2.MarginRight = 2.5
End With
Next i




End Sub

Any help is greatly appreciated. If you want a copy of the original file please let me know.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Re: New to VBA. Need some TextBox backcolor help

You could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.

Explain a couple of examples what you need
 
Upvote 0
Re: New to VBA. Need some TextBox backcolor help

You could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.

Explain a couple of examples what you need

https://drive.google.com/open?id=15sbO-k051wuPDGPkP2BxiEz1LX0GxabO

I'm looking now to input the state abbreviation, then a line break, and then the data associated with the given state. Any help is greatly appreciated.

Thank you in advance.
 
Upvote 0
Re: New to VBA. Need some TextBox backcolor help

https://drive.google.com/open?id=15sbO-k051wuPDGPkP2BxiEz1LX0GxabO

I'm looking now to input the state abbreviation, then a line break, and then the data associated with the given state. Any help is greatly appreciated.

Thank you in advance.


Do not have problems with the color?
I executed the macro and the Textbox backcolor/fillcolor is equal the state color.

Where do you want to enter abbreviation and where do you want the result?
 
Upvote 0
Re: New to VBA. Need some TextBox backcolor help

Do not have problems with the color?
I executed the macro and the Textbox backcolor/fillcolor is equal the state color.

Where do you want to enter abbreviation and where do you want the result?

I corrected the color issue. I need to have the abbreviation on the first line in the text box and the number on the 2nd line.

Example:

FL
200
 
Upvote 0
Re: New to VBA. Need some TextBox backcolor help

Try this:

Code:
Sub Paint()


    Dim i As Integer
    For i = 1 To 51
        'First, paint the state shapes
        Range("actorder").Value = i
        ActiveSheet.Shapes(Range("actstate").Value).Fill.ForeColor.RGB = _
        Range(Range("actcolorcode").Value).Interior.Color
        
        ActiveSheet.Shapes(Range("acttext").Value).Select
        With Selection
            'Second, update the text boxes
[COLOR=#0000ff]            .Text = Range("acttextvalue").Value & vbCr & _[/COLOR]
[COLOR=#0000ff]                    Range("actstatevalu").Value[/COLOR]
            
            '(Optional) Format the text boxes
            .ShapeRange.Fill.ForeColor.RGB = _
            Range(Range("actcolorcode").Value).Interior.Color
            .ShapeRange.Fill.Transparency = 0
            .ShapeRange.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 0, 0)
            .ShapeRange.TextFrame2.TextRange.Font.Shadow.Visible = False
            '.ShapeRange.TextFrame2.MarginLeft = 2.5
            '.ShapeRange.TextFrame2.MarginRight = 2.5
        End With
    Next i


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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