Peskarik
01-31-2008, 09:02 AM
Hello,
I am a total rookie when it comes to VBA, used it for 2 days. I am reading a book and experimenting, and got into trouble. Cannot understand what I am doing wrong. :dunno
background and question:
I have an open workbook with 2 worksheets: "Shading" and "main". I want to shade every second row in Shading as long as there are values in the first column (I have values 1 thru 25 in column A). The code for this I have from the VBA bible, but I wanted to play a little by running the procedure while "main" is selected. And it does not work. But if I select "Shading" and run the procedure - it works. Could someone please explain why it does not work? :banghead: Is "With" statement incorrectly specified? Thanks in advance! :friends:
Module1 code:
Option Explicit
Sub ShadeEverySecondRow()
With ThisWorkbook.Worksheets("Shading")
.Range("A2").EntireRow.Select
Do While ActiveCell.Value <> ""
Selection.Interior.ColorIndex = 15
ActiveCell.Offset(2, 0).EntireRow.Select
Loop
End With
End Sub
I am a total rookie when it comes to VBA, used it for 2 days. I am reading a book and experimenting, and got into trouble. Cannot understand what I am doing wrong. :dunno
background and question:
I have an open workbook with 2 worksheets: "Shading" and "main". I want to shade every second row in Shading as long as there are values in the first column (I have values 1 thru 25 in column A). The code for this I have from the VBA bible, but I wanted to play a little by running the procedure while "main" is selected. And it does not work. But if I select "Shading" and run the procedure - it works. Could someone please explain why it does not work? :banghead: Is "With" statement incorrectly specified? Thanks in advance! :friends:
Module1 code:
Option Explicit
Sub ShadeEverySecondRow()
With ThisWorkbook.Worksheets("Shading")
.Range("A2").EntireRow.Select
Do While ActiveCell.Value <> ""
Selection.Interior.ColorIndex = 15
ActiveCell.Offset(2, 0).EntireRow.Select
Loop
End With
End Sub