Microsoft Excel 2007 Visual Basic for Applications (VBA) macros


Usually requires Internet Explorer (Microsoft IE) web browser: Excel 97, Excel 2003 VBA Macros tutorial - converted from PowerPoint.
Even though this is for Excel 2003 and earlier versions, the Visual Basic for Applications concepts and code are identical.



What is the output of the following VBA macro code? Draw a rectangular grid and show the row numbers and column letters and exactly what the Excel worksheet would look like after running the macro. Assume that the macro was executed using the above worksheet as the active worksheet.
Sub practiceVBA()
    theString = Cells(9, 9).Value
    
    Cells(9, 10).Value = Len(theString)
    
    For i = 1 To Len(theString)
        Cells(i, 12).Value = Left(theString, i)
    Next i
    
    theNumber = 1
    For j = 1 To Len(theString) Step 2
        
        Cells(14, j).Value = j * j
        Cells(theNumber, theNumber).Value = Mid(theString, theNumber, 1)
        
        theNumber = theNumber + 1
    Next j
    
    
    Range("E3").Value = Range("F1").Value & " " & Range("G1").Value
    
    Cells(2, 5).Value = Cells(2, 6).Value + Cells(2, 7).Value + 9 + 9 + 9
End Sub


VIP: Friday, September 4th Excel VBA macros page.