PSS ID Number: 141572
Article Last Modified on 5/13/2002
Sub Test1()
Dim x As Integer
' Set numrows = number of rows of data.
NumRows = Range("A2", Range("A2").End(xldown)).Rows.Count
' Select cell a1.
Range("A2").Select
' Establish "For" loop to loop "numrows" number of times.
For x = 1 To NumRows
' Insert your code here.
' Selects cell down 1 row from active cell.
ActiveCell.Offset(1, 0).Select
Next
End Sub
Sub Test2()
' Select cell A2, *first line of data*.
Range("A2").Select
' Set Do loop to stop when an empty cell is reached.
Do Until IsEmpty(ActiveCell)
' Insert your code here.
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
End Sub
NOTE: If there are empty cells in column A throughout the data, then
you can modify this code to account for this condition, as long as
empty cells are a consistent distance apart. For example, if every
other cell in column A is empty (this might occur if every 'record'
uses two rows, with the second row indented one cell, for example), this
loop can be modified as follows:
' Set Do loop to stop when two consecutive empty cells are reached.
Do Until IsEmpty(ActiveCell) and IsEmpty(ActiveCell.Offset(1, 0))
' Insert your code here.
'
' Step down 2 rows from present location.
ActiveCell.Offset(2, 0).Select
Loop
Sub Test3()
Dim x As String
Dim found As Boolean
' Select first line of data.
Range("A2").Select
' Set search variable value.
x = "test"
' Set Boolean variable "found" to false.
found = False
' Set Do loop to stop at empty cell.
Do Until IsEmpty(ActiveCell)
' Check active cell for search value.
If ActiveCell.Value = x Then
found = TRUE
Exit Do
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
' Check for found.
If found = True Then
Msgbox "Value found in cell " & ActiveCell.Address
Else
Msgbox "Value not found"
End If
End Sub
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 5.00a 5.00c 8.00 xl97
Keywords: kbdtacode kbhowto kbProgramming KB141572
Technology: kbExcel500 kbExcel500aMac kbExcel500c kbExcel500Mac kbExcel95 kbExcel95Search kbExcel97Search kbExcelMacsearch kbExcelSearch kbExcelWinSearch kbHWMAC kbOSMAC kbVBASearch kbZNotKeyword3 kbZNotKeyword6