How to execute F5 in text boxes when a slicer changes

jevi

Active Member
Joined
Apr 13, 2010
Messages
339
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I have text boxes with values like this
1648831832669.png

which they get the data from an excel sheet K166:P167 and is connected with a slicer with you can choose to view the data of Gen, Feb and March. So the textboxes are connected with =K166, the other one, L166 etc etc. But if in the cells of excel sheet the values are conditional formatting with the colours but in the textboxes they don't keep the conditional formatting and I would like to color them in automatic so when is ▲ green and when is ▼ red. I don't know how to do it with text boxes.

Jamie gave me help and I have this macro with works but when I click on the slicer to choose the month of the data to view everytime I need to click the macro...so It doesn't do it automatically and it will be nicer to do it automatically.

Thank you,

VBA Code:
Sub ChangeColourTwo()
If Range("K166").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 1")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 1")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("L166").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 2")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 2")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("M166").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 3")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 3")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("N166").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 4")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 4")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("O166").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 5")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 5")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("P166").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 6")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 6")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("K167").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 7")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 7")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("L167").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 8")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 8")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("M167").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 9")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 9")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("N167").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 10")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 10")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("O167").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 11")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 11")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
If Range("P167").Value < 0 Then
ActiveSheet.Shapes.Range(Array("TextBox 12")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255, 0, 0) 'change TextBox 1 to your Textbox name
Else
ActiveSheet.Shapes.Range(Array("TextBox 12")).TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 176, 80)
End If
End Sub

IMPORTANT:- Right click on the sheet tab and choose view code; paste the code below

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("K166:P167")) Is Nothing Then
Call ChangeColour
End If
End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,901
Messages
6,122,157
Members
449,068
Latest member
shiz11713

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