Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub LoopThroughRange()
Const FirstUsedRow = 4 'Make this your specified first cell
Const ColNum = 1 'Make this your column (A=1, B=2, etc.)
Dim LastUsedRow As Long
Dim Rng As Range
Dim OneCell As Range
With ActiveSheet
If .Cells(65536, ColNum).Value <> "" Then
LastUsedRow = 65536
Else
LastUsedRow.Cells(65536, ColNum).End(xlUp).Row
End If
Set Rng = .Range(.Cells(FirstUsedRow, ColNum), .Cells(LastUsedRow, ColNum))
For Each OneCell In Rng
'Do stuff with each cell here
Next OneCell
End With
End Sub
Option Explicit
Sub Demo()
Dim WorkArea As Range
Dim WorkCell As Range
Dim nEmptyCount As Integer
Dim nRowOffset As Integer
Set WorkArea = Selection
' or whatever for first cell
nEmptyCount = 0
nRowOffset = -1
While nEmptyCount < 3
nRowOffset = nRowOffset + 1
Set WorkCell = WorkArea.Offset(nRowOffset, 0)
If WorkCell.Value = "" Then
nEmptyCount = nEmptyCount + 1
Else
nEmptyCount = 0
With WorkCell
' Insert your code here...
MsgBox .Address
End With
End If
Wend
Set WorkArea = Nothing
Set WorkCell = Nothing
End Sub
LastUsedRow = .Cells(65536,ColNum).End(xlUp).Row