Macro to run on multiple and selected worksheets

K0st4din

Active Member
Joined
Feb 8, 2012
Messages
488
Office Version
  1. 2016
  2. 2013
  3. 2011
  4. 2010
  5. 2007
Platform
  1. Windows
Hello, everyone,
I made 3 macros by hand with clicks.
I would like to ask if someone can help and make each of the macros separately (individually, I'll make a button) to be able to run in 30 worksheets, eg London, Paris, Germany, etc. to the end.
Because now I do this thing by opening every single worksheet and it takes me an awful lot of time.
I have necessarily left in the macro which cells I marked, because after a while I will have to run the same macro, but in neighboring cells.
Thank you in advance!
Be healthy!
VBA Code:
Sub test2BLACK()

Application.ScreenUpdating = True
    Range("O62:Z62").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=N62<O62"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = True
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .Pattern = xlNone
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.ScreenUpdating = False
End Sub
Code:
Sub TEST3RED()
Application.ScreenUpdating = True
    Range("P62:Z62").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=O62>P62"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = True
        .Color = -16776961
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .Pattern = xlNone
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.ScreenUpdating = False
End Sub

Code:
Sub table()
Application.ScreenUpdating = True
    Range("O3:Z60").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=O3=MAX($O3:$Z3)"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = True
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent3
        .TintAndShade = 0.599963377788629
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=LEN(TRIM(O3))=0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .Pattern = xlNone
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Application.ScreenUpdating = False
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Now when I clicked on just one worksheet it gave me an error in all three macros here:
2022-12-11_085601.jpg
2022-12-11_085901.jpg
 
Upvote 0
Hello
does anyone have any idea how to do this?
After I did it manually and tested the macro, it gave me an error in itself. After that I read and searched on the internet and it struck me that when this conditional formatting was used it was more special. That is, the macro was written in a slightly different way.
I am also attaching an example table, in a finished version, after I have manually set the range and coloring of the necessary cells.
test brt.xlsm
ABCDEFGHIJKLMNO
1
220211.20222.20223.20224.20225.20226.20227.20228.20229.202210.202211.202212.20222022
3
4374353455045743255535
51151813107161214613
6-1391940163428432932
74234434846363237363938
814914814131116141013
9184148192185203161164227172187189
10
11
122723162018214221272426
13-11
14293040405356444867143178
151551512101672131682072105214
16116126521516302247
171112152126172222161221
1896429543-3
19152111169
201214151717121617112214
213588711
22
239201771091627222237
247324375667
252021292213192522232035
263
27751-1111
281517341917333018233128
296669615986737074717174
30
31
32
3316771448175716121823177417641944188220231977
34
35
361112-131
3782717683111698254729781
38
39
402841355025322942324536
413311201241131091516
4251411121531268522
4333264047205478810
44203367748476553787676
455849705055525353465459
461214121017110
47194188225232227219205250256267303
48669411443
494029374345343639363832
50
5114412614712613610412910813299116
521417172018171616162210
53
545554596055544043473837
55207155203201198184198197182193209
561812221818202122222522
571910141616171427294451
58787384976810
594159667055556178829088
6075474-2841167
61
6233452964368534593727343135163817362038743981
63
london

2022-12-12_062952.jpg

VBA Code:
Sheets(Array("LONDON", "PARIS", ECT......)).Select
That's it, I don't know how to add it and if it's possible in principle
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,686
Members
449,249
Latest member
ExcelMA

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