Excel VBA Formatting Cells in a Different Workbook

Thank you for looking at my question,

I am trying to apply some formatting to cells in a different workbook than the user is working in.

I want to fill the header row with a colour to differentiate header from data.

The number of columns in the target worksheet depends on a value set by the user (intPeriodRange)

The code I have tried is as below but it doesn't work - how should I change it so that the colour fill works please?


    With sheetobject.Range(Cells(1, 1), Cells(2, intPeriodRange + 6)).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorAccent5
        .TintAndShade = 0.599963377788629
        .PatternTintAndShade = 0
    End With
Gary CroxfordOperations Support AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try

    With sheetobject.Range(Cells(1, 1), Cells(1, intPeriodRange + 6)).Interior
         .Pattern = xlSolid
         .PatternColorIndex = xlAutomatic
         .ThemeColor = xlThemeColorAccent5
         .TintAndShade = 0
         .PatternTintAndShade = 0
    End With
    With sheetobject.Range(Cells(2, 1), Cells(2, intPeriodRange + 6)).Interior
         .Pattern = xlSolid
         .PatternColorIndex = xlAutomatic
         .ThemeColor = xlThemeColorAccent5
         .TintAndShade = 0.599963377788629
         .PatternTintAndShade = 0
    End With
End Sub

Open in new window

Regards
0
Gary CroxfordOperations Support AnalystAuthor Commented:
Rgonzo,

this didn't make any change
0
Rgonzo1971Commented:
Could you send a dummy? with actual and desired result
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Gary CroxfordOperations Support AnalystAuthor Commented:
Rgonzo,

Have attached the file that is output (Actual), how I hoped it would look (Desired), the code that produces the result and the source data
Period-Issue---Actual.xlsx
Period-Issue---Desired.xlsx
Process-Period-Issue-Data.xlsm
PeriodIssueData.csv
0
Rgonzo1971Commented:
then try

    With sheetobject.Range(Cells(1, 1), Cells(2, intPeriodRange + 6)).Interior
         .Pattern = xlSolid
         .Color = RGB(142, 169, 219)
    End With

Open in new window

0
Gary CroxfordOperations Support AnalystAuthor Commented:
RGonzo1971,

This didn't make any change either.

Using
    With sheetobject.range("A1:Q2").Interior
         .Pattern = xlSolid
         .Color = RGB(142, 169, 219)
    End With

does apply the colour format but this isn't dynamic
0
Rgonzo1971Commented:
on you code you use

On Error Resume Next this not be used for all the code you cannot see where error appears

the line MyExcelFilePath = "C:\YourFolder\Period-Issue.xlsx" has a blank instead of -
No error and sheetobject not created since On error resume next

pls revise your code
0
Gary CroxfordOperations Support AnalystAuthor Commented:
Rgonzo1971,

The dashes are put into the filenames when they are uploaded to EE.

The line MyExcelFilePath = "C:\YourFolder\Period Issue.xlsx"  should have a blank.

I know this because there has already been a lot of processing on the data before we get to the issue of formatting the target file and that runs fine.

I have removed the On Error Resume Next statement
0
Rgonzo1971Commented:
Hi,

pls try

With sheetobject.Range(sheetobject.Cells(1, 1), sheetobject.Cells(2, intPeriodRange + 6)).Interior
         .Pattern = xlSolid
         .Color = RGB(142, 169, 219)
    End With

Open in new window

0
Rgonzo1971Commented:
or

    With sheetobject
        With .Range(.Cells(1, 1), .Cells(2, intPeriodRange + 6)).Interior
             .Pattern = xlSolid
             .Color = RGB(142, 169, 219)
        End With
    End With

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gary CroxfordOperations Support AnalystAuthor Commented:
Bingo! Thank you for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.