Interior.Color Issues

Pestomania

Active Member
Joined
May 30, 2018
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hi. So I am using a userform to determine the color of a sheet. But it keeps having issues getting past one sheet. I'll show the code below.

Code:
Sub ColorAllSheets ()

Dim wsd as worksheet
Application.DisplayAlerts = False
For each wsd in worksheets  If left(wsd.name,4) = "asse" or left(wsd.name,4)="ASSE" then
Wsd.select

Eun "Userform_Initialize"

End if
Next WSD

End sub
At this point a user form pops up with four buttons "SMALL, MEDIUM, LARGE, NONE"

When the user selects a button it will color a specific range of cells.
An example:
Code:
Sub ColorYellow()
Range("T13:U21").Select
   With Selection.Interior
        .Color = RGB(255,255,0)
        .TintAndShade = 0
   End With
End Sub

It works for one sheet but when it goes to the second it says that the "RunTime Error 1004" "Application-Defined or object defined erroe" and it highlights .Color = RGB.

I don't know why it works once but not twice or third.
 
Last edited:

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
I made a few small changes to the code when doing a test, and it worked for me....

first I used userform.show instead of what I assume should have been "Run "Userform_Initialize"

also, I used a Lcase to cover all versions of the first four letters such as "Asse", "ASSE", "asse", or "AsSe"

Code:
Sub ColorAllSheets()

Dim wsd As Worksheet
Application.DisplayAlerts = False
For Each wsd In Worksheets
If LCase(Left(wsd.Name, 4)) = "asse" Then
wsd.Select

UserForm1.Show

End If
Next wsd

End Sub


In the Userform I only tested with one button but this was everything I used:

Code:
Private Sub CommandButton1_Click()
ColorYellow
Me.Hide
End Sub

Sub ColorYellow()
Range("T13:U21").Select
   With Selection.Interior
        .Color = RGB(255, 255, 0)
        .TintAndShade = 0
   End With
End Sub

and it seemed to work fine,
 
Upvote 0
So you only have one worksheet the script is selecting?
Is that true?

When I test your script it works but only if you have one sheet with the first four character that meet your requirements.

And why do you need the Userform to perform this task.
 
Upvote 0
Code:
Private Sub CommandButton1_Click()
  Range("T13:U21").Interior.Color = vbYellow
  Me.Hide
End Sub
 
Upvote 0
Now that I look closer it is working.

But there is surely a easier way to do this:

Do you really need a Userform?
 
Upvote 0
Why would one script just like this not work.
No need for a UserForn

Code:
Sub Color_My_Ranges()
'Modified  10/23/2018  4:44:37 PM  EDT
Dim wsd As Worksheet
Application.ScreenUpdating = False
    For Each wsd In Worksheets
        If LCase(Left(wsd.Name, 4)) = "asse" Then
            With wsd.Range("T13:U21").Interior
                .Color = RGB(255, 255, 0)
                .TintAndShade = 0
            End With
        End If
    Next wsd
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
So you only have one worksheet the script is selecting?
Is that true?

When I test your script it works but only if you have one sheet with the first four character that meet your requirements.

And why do you need the Userform to perform this task.

Hello. The workbook can have 1 where or 10 or 50. No set amount. And the user needs a way to color each individual sheet, which is why I did the userform.
 
Upvote 0
Hello. There are other color options, I only inputted one. With the userform they would select one of the four options.
 
Upvote 0
Hi everyone. So I wanted to state some clarification.

There are 4 color options on the userform, I only posted one. Also, there are multiple sheets that meet the criteria. The left function cycles through the sheets perfectly!

But after selecting one color option and the program goes to the second worksheet, the color code crashes.
 
Upvote 0
I now understand what your wanting to do.
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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