Results 1 to 5 of 5

Issues with running a Procedure in Excel 2003

Threaded View

saurabhpunn Issues with running a... 05-14-2012, 08:05 AM
JBeaucaire Re: Issues with running a... 05-14-2012, 08:34 AM
rvasquez Re: Issues with running a... 05-14-2012, 08:35 AM
saurabhpunn Re: Issues with running a... 05-15-2012, 06:16 AM
rvasquez Re: Issues with running a... 05-15-2012, 09:07 AM
  1. #1
    Registered User
    Join Date
    05-14-2012
    Location
    Gurgaon
    MS-Off Ver
    Excel 2003
    Posts
    2

    Issues with running a Procedure in Excel 2003

    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
    Last edited by arlu1201; 05-14-2012 at 08:07 AM. Reason: Please use code tags in future as per forum rules.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1