Automatically Center Across Selection and Fill Based on Number in another Cell

RLBrown

New Member
Joined
Aug 6, 2018
Messages
25
I'm working on an event calendar and need to have the event listed in the week it starts then fill color in cells for the number of weeks that the event will run.
If possible, centering the event across the selection horizontally would be ideal. The the weeks listed in the calendar will never change as there is no 'date'.
Worksheet showing where I am currently and my end goal is attached. --- Thank You To All.
 

Attachments

  • Screenshot 2022-02-16 142513.jpg
    Screenshot 2022-02-16 142513.jpg
    101.5 KB · Views: 35

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You are very welcome. :)
(No good deed goes unpunished -- Oscar Wilde)

As stated above, your solution worked beautifully --- until I added a new promo (row). How or what do I need to do to enable (prompt?) the macro to apply to new rows?
 
Upvote 0
If the new row is directly underneath, the macro should work as written. If it doesn’t work, please post an updated sheet.
 
Upvote 0
Kroger Promo Master Jan2022 v2 practice.xlsm
ACDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJ
1 Calendar 2022P1 WK1P2 WK1P3P4P5P6P7P8P9P10P11P12P13
2Pd'BrandDescriptionPromo TypePromo Start# of WeeksContract StatusContract DuePromo PriceP1 WK1P1 WK2P1 WK3P1 WK4P2 WK1P2 WK2P2 WK3P2 WK4P3 WK1P3 WK2P3 WK3P3 WK4P4 WK1P4 WK2P4 WK3P4 WK4P5 WK1P5 WK2P5 WK3P5 WK4P6 WK1P6 WK2P6 WK3P6 WK4P7 WK1P7 WK2P7 WK3P7 WK4P8 WK1P8 WK2P8 WK3P8 WK4P9 WK1P9 WK2P9 WK3P9 WK4P10 WK1P10 WK2P10 WK3P10 WK4P11 WK1P11 WK2P11 WK3P11 WK4P12 WK1P12 WK2P12 WK3P12 WK4P13 WK1P13 WK2P13 WK3P13 WK4
3P2BMBECL 5OZMEGAP2 WK1211/19/21$0.69CL 5OZ MEGA
4P2BMBECL 5OZKATSP2 WK3412/03/21$0.79
5P3BMBECL 5OZEDLPP3 WK31212/31/21$0.99
6P5BMBECL 5OZKATSP5 WK1602/11/22$0.79
7P2BMBEPOUCH 2.5OZKATSP2 WK1411/19/2110/$10POUCH 2.5OZ KATS
8P3BMBEPOUCH 2.5OZEDLPP3 WK11312/17/214/$5
9P4BMBEPOUCH 2.5OZKATSP4 WK3801/28/2210/$10
10P1BMBECL 12OZEDLPP1 WK1610/22/21$2.79CL 12OZ EDLP
11P3BMBECL 12OZEDLPP3 WK21312/24/21$2.79
12P3BMBESW 4CT 5OZEDLPP3 WK21312/24/21$9.79
13P2BMBECW 5OZEDLPP2 WK2911/26/21$1.69
14P2BMBECW 5OZKATSP2 WK2411/26/213/$4
15P4BMBECW 5OZEDLPP4 WK3801/28/22$1.79
16P5BMBECW 5OZKATSP5 WK1402/11/223/$4
17P2BMBECL 4CT 5OZSEAS LOWP2 WK2911/26/21$6.99
18P2BMBEPRIME 5OZKATSP2 WK1411/19/212/$5PRIME 5OZ KATS
19P2BMBESW 12OZSEAS LOWP2 WK2911/26/21$3.99
20P3BMBESW 3CT 3OZEDLPP3 WK21312/24/21$3.49
21P2BMBESW 5OZSEAS LOWP2 WK2911/26/21$1.99
22P1BMBECL 3CT 3OZEDLPP1 WK1510/22/21$3.99CL 3CT 3OZ EDLP
23P1BMBEKITS SOTREDLPP1 WK1510/22/214/$6KITS SOTR EDLP
24P2BMBEKITS SOTRSEAS LOWP2 WK2911/26/214/$6
25P2BMBETRAD. SARD.SEAS LOWP2 WK2911/26/2110/$10
26P3BMBESALMON - RED TALLSKATSP3 WK1412/17/21$3.99
27P2BMBESALMON - RED <14OZKATSP2 WK1411/19/21$4.99SALMON - RED <14OZ KATS
28P2BMBECLAMSKATSP2 WK1811/19/213/$5CLAMS KATS
29P2BMBECLAM JUICEKATSP2 WK1811/19/212/$4CLAM JUICE KATS
30P2BMBEOYSTERSKATSP2 WK1411/19/212/$4OYSTERS KATS
31#N/A
32#N/A
005PromoMaster
Cell Formulas
RangeFormula
I3:I32I3=VLOOKUP($F3,Lookup!$R$2:$S$53,2,0)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I:ICellcontains an errortextNO
H3:H50Cell Valuecontains "SUBMITTED"textNO
H3:H50Cell Valuecontains "REJECTED"textNO
H3:H50Cell Valuecontains "ACCEPTED"textNO
K3:BJ47Celldoes not contain a blank value textNO
Cells with Data Validation
CellAllowCriteria
A3:A59List=Lookup!$M$1:$M$14
C3:C50List=Lookup!L$11:L$16
D3List=Lookup!$O$3:$O$35
E3:E102List=Lookup!$L$1:$L$9
F3:F97List=Lookup!R$1:R$53
D4:D50List=Lookup!$O$2:$O$35
H3:H32List=Lookup!X$1:X$4
 
Upvote 0
Kroger Promo Master Jan2022 v2 practice.xlsm
ACDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJ
1 Calendar 2022P1 WK1P2 WK1P3P4P5P6P7P8P9P10P11P12P13
2Pd'BrandDescriptionPromo TypePromo Start# of WeeksContract StatusContract DuePromo PriceP1 WK1P1 WK2P1 WK3P1 WK4P2 WK1P2 WK2P2 WK3P2 WK4P3 WK1P3 WK2P3 WK3P3 WK4P4 WK1P4 WK2P4 WK3P4 WK4P5 WK1P5 WK2P5 WK3P5 WK4P6 WK1P6 WK2P6 WK3P6 WK4P7 WK1P7 WK2P7 WK3P7 WK4P8 WK1P8 WK2P8 WK3P8 WK4P9 WK1P9 WK2P9 WK3P9 WK4P10 WK1P10 WK2P10 WK3P10 WK4P11 WK1P11 WK2P11 WK3P11 WK4P12 WK1P12 WK2P12 WK3P12 WK4P13 WK1P13 WK2P13 WK3P13 WK4
3P2BMBECL 5OZMEGAP2 WK1211/19/21$0.69CL 5OZ MEGA
4P2BMBECL 5OZKATSP2 WK3412/03/21$0.79
5P3BMBECL 5OZEDLPP3 WK31212/31/21$0.99
6P5BMBECL 5OZKATSP5 WK1602/11/22$0.79
7P2BMBEPOUCH 2.5OZKATSP2 WK1411/19/2110/$10POUCH 2.5OZ KATS
8P3BMBEPOUCH 2.5OZEDLPP3 WK11312/17/214/$5
9P4BMBEPOUCH 2.5OZKATSP4 WK3801/28/2210/$10
10P1BMBECL 12OZEDLPP1 WK1610/22/21$2.79CL 12OZ EDLP
11P3BMBECL 12OZEDLPP3 WK21312/24/21$2.79
12P3BMBESW 4CT 5OZEDLPP3 WK21312/24/21$9.79
13P2BMBECW 5OZEDLPP2 WK2911/26/21$1.69
14P2BMBECW 5OZKATSP2 WK2411/26/213/$4
15P4BMBECW 5OZEDLPP4 WK3801/28/22$1.79
16P5BMBECW 5OZKATSP5 WK1402/11/223/$4
17P2BMBECL 4CT 5OZSEAS LOWP2 WK2911/26/21$6.99
18P2BMBEPRIME 5OZKATSP2 WK1411/19/212/$5PRIME 5OZ KATS
19P2BMBESW 12OZSEAS LOWP2 WK2911/26/21$3.99
20P3BMBESW 3CT 3OZEDLPP3 WK21312/24/21$3.49
21P2BMBESW 5OZSEAS LOWP2 WK2911/26/21$1.99
22P1BMBECL 3CT 3OZEDLPP1 WK1510/22/21$3.99CL 3CT 3OZ EDLP
23P1BMBEKITS SOTREDLPP1 WK1510/22/214/$6KITS SOTR EDLP
24P2BMBEKITS SOTRSEAS LOWP2 WK2911/26/214/$6
25P2BMBETRAD. SARD.SEAS LOWP2 WK2911/26/2110/$10
26P3BMBESALMON - RED TALLSKATSP3 WK1412/17/21$3.99
27P2BMBESALMON - RED <14OZKATSP2 WK1411/19/21$4.99SALMON - RED <14OZ KATS
28P2BMBECLAMSKATSP2 WK1811/19/213/$5CLAMS KATS
29P2BMBECLAM JUICEKATSP2 WK1811/19/212/$4CLAM JUICE KATS
30P2BMBEOYSTERSKATSP2 WK1411/19/212/$4OYSTERS KATS
31#N/A
32#N/A
005PromoMaster
Cell Formulas
RangeFormula
I3:I32I3=VLOOKUP($F3,Lookup!$R$2:$S$53,2,0)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I:ICellcontains an errortextNO
H3:H50Cell Valuecontains "SUBMITTED"textNO
H3:H50Cell Valuecontains "REJECTED"textNO
H3:H50Cell Valuecontains "ACCEPTED"textNO
K3:BJ47Celldoes not contain a blank value textNO
Cells with Data Validation
CellAllowCriteria
A3:A59List=Lookup!$M$1:$M$14
C3:C50List=Lookup!L$11:L$16
D3List=Lookup!$O$3:$O$35
E3:E102List=Lookup!$L$1:$L$9
F3:F97List=Lookup!R$1:R$53
D4:D50List=Lookup!$O$2:$O$35
H3:H32List=Lookup!X$1:X$4
when I add rows the macro doesn't apply. Also weird not all of the previously shown information is visible after I run the macro (again). I apologize for being a pain in the tukus, but at a complete loss =( my whole sheet range will be A1:BJ102
Many thanks, RLBrown
 
Upvote 0
Try:
VBA Code:
Sub FillRange()
    Application.ScreenUpdating = False
    Dim PromoSt As Range, fnd As Range, LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    With Range("K3:BJ" & LastRow)
        .ClearContents
        .Interior.ColorIndex = xlNone
        .Font.ColorIndex = 2
    End With
    For Each PromoSt In Range("F3:F" & LastRow)
        Set fnd = Rows(2).Find(PromoSt, LookIn:=xlValues, lookat:=xlWhole)
        If Not fnd Is Nothing Then
            Cells(PromoSt.Row, fnd.Column) = PromoSt.Offset(, -2) & " " & PromoSt.Offset(, -1)
            With Cells(PromoSt.Row, fnd.Column).Resize(, PromoSt.Offset(, 1))
                .HorizontalAlignment = xlCenterAcrossSelection
                .Interior.ColorIndex = 3
            End With
        End If
    Next PromoSt
    Application.ScreenUpdating = True
End Sub
I have modified the code to clear any old data and colors.
 
Upvote 0
Solution
Thank you, I replaced the old code and ran; received run-time error as follows. If you are at the end of your rope with me I completely understand.

Run-time error ‘1004:

Application-defined or object-defined error

**************************************************************

When ‘debug’ line 14 identified:

With Cells (PromoSt.Row, fnd.Column) .Resize(, PromoSt.Offset(, 1))
 
Upvote 0
Please step through the code one line at a time. You can do this by placing the cursor anywhere in the code and pressing the F8 key. Each press of the key will execute one line of code. When this line of code is highlighted:
VBA Code:
With Range("K3:BJ" & LastRow)
place the cursor over "LastRow" and you will see the value of that variable. Check your data to see if the number returned matches the last row with data in your sheet.
 
Upvote 0
Yes, each instance of 'LastRow' is 102, the last row with data. The macro runs and all events (old & new) appear.
Still receiving runtime error each time the macro is run. Pasting image with highlight showing what clicking 'debug' shows.

If I click 'end' the process ends and new & old information appear --- I can press 'end' as part of the process and happily use this worksheet. But I also wanted to show/tell you what i'm seeing. Thanks


1645307054743.png
 
Upvote 0
Click here to download your file. Please note that in column, rows 31 and 32, you have formulas. Therefore, I31 and I32, although they look blank, are not actually blank so the actual last row is not 30 but 32. Delete rows 31 and 32 and try the macro again. Also, please note that each time you run the macro, all the old information is deleted before being replaced with the new data.
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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