VBA question - I am trying to execute this code when I enter my excel SHEET

Status
Not open for further replies.

RudeBoy

Active Member
Joined
Feb 2, 2003
Messages
376
VBA question - I am trying to execute this code when I enter my excel SHEET

Here is my VBA CODE:
'CODE to Turn TIES to YELLOW'

Private Sub Workbook_Open()
Dim lr As Long, i As Long, clr As Long
clr = 6
Sheet3.Activate
Sheet3.Cells.Interior.Color = xlNone
lr = Cells(Rows.Count, "A").End(xlUp).Row
lr = lr - 2
For i = 4 To lr Step 6
If Cells(i, 3) = Cells(i, 7) And Cells(i, 3) = Cells(i, 11) Then
Cells(i, 3).Interior.ColorIndex = clr
Cells(i, 7).Interior.ColorIndex = clr
Cells(i, 11).Interior.ColorIndex = clr
ElseIf Cells(i, 3) = Cells(i, 7) Then
Cells(i, 3).Interior.ColorIndex = clr
Cells(i, 7).Interior.ColorIndex = clr
ElseIf Cells(i, 3) = Cells(i, 11) Then
Cells(i, 3).Interior.ColorIndex = clr
Cells(i, 11).Interior.ColorIndex = clr
ElseIf Cells(i, 7) = Cells(i, 11) Then
Cells(i, 7).Interior.ColorIndex = clr
Cells(i, 11).Interior.ColorIndex = clr
End If
Next i

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
VBA question - I am trying to execute this code when I enter my excel SHEET

Here is my VBA CODE:
'CODE to Turn TIES to YELLOW'

Private Sub Workbook_Open()
Dim lr As Long, i As Long, clr As Long
clr = 6
Sheet3.Activate
Sheet3.Cells.Interior.Color = xlNone
lr = Cells(Rows.Count, "A").End(xlUp).Row
lr = lr - 2
For i = 4 To lr Step 6
If Cells(i, 3) = Cells(i, 7) And Cells(i, 3) = Cells(i, 11) Then
Cells(i, 3).Interior.ColorIndex = clr
Cells(i, 7).Interior.ColorIndex = clr
Cells(i, 11).Interior.ColorIndex = clr
ElseIf Cells(i, 3) = Cells(i, 7) Then
Cells(i, 3).Interior.ColorIndex = clr
Cells(i, 7).Interior.ColorIndex = clr
ElseIf Cells(i, 3) = Cells(i, 11) Then
Cells(i, 3).Interior.ColorIndex = clr
Cells(i, 11).Interior.ColorIndex = clr
ElseIf Cells(i, 7) = Cells(i, 11) Then
Cells(i, 7).Interior.ColorIndex = clr
Cells(i, 11).Interior.ColorIndex = clr
End If
Next i

End Sub
So what is happening?
This script should run when you open your workbook.
 
Upvote 0
Works fine for me...
Do you have a Sheet3 ??
AND
Is it the correct sheet ??
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,515
Messages
6,125,279
Members
449,220
Latest member
Excel Master

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