Hi,
I'm new to VBA and following a book called Mastering Excel 2003 Programming with VBA to learn. I'm stuck on one of the examples given in the book. Please see the details below:
1: I've created an Excel sheet under C:\Examples\ named Example.xls. The sheet1 os the excel has data in Column B3 (="animal"), Column B4 (="art") and Column B5 (="test"). The pupose of the code (Below) is to make the column bold if the data starts with "a".
2: As given in the book, I've added a module to this sheet & copied the below code to the module:
Sub SimpleListProcessing()
' Declare our varibles
Dim wb As Workbook
Dim rg As Range
' Initialize our variables
Set wb = Workbooks.Open("C:\Examples\Example.xls")
Set rg = wb.Worksheets("Sheet1").Range("B3")
' Loop through cells moving down one cell
' until an empty cell is found
Do Until IsEmpty(rg)
If Left(rg.Value, 1) = "A" Then rg.Font.Bold = True
Set rg = rg.Offset(1, 0)
Loop
' Dereference object variables
Set rg = Nothing
Set wb = Nothing
End Sub
3: However, when I try to execute the above mentioned code, the strange thing is that Nothing Happens. What I mean is that No Error is thrown & nor does the data in sheet1 is made bold.
Can someone pls help me understand what exactly is the issue here?
Note: Just to make sure if other piece of code is running through a module, I added the below code to module & it works (Gives me an Output):
Sub ExitForExample()
Dim nLastRow As Integer
Dim nColumn As Integer
Dim nRow As Integer
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets(1)
nLastRow = 15
nColumn = 1
For nRow = 1 To nLastRow
If ws.Cells(nRow, nColumn).Address = "$A$7" Then
Debug.Print "Found cell. Exiting for loop."
Exit For
Else
Debug.Print ws.Cells(nRow, nColumn).Address
End If
Next
Set ws = Nothing
End Sub
Bookmarks