Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata
Public Sub ForEachRng()

Dim rcell As Range, rng As Range

Set rng = UsedRange

For Each rcell In rng.Cells
 If Not IsError(rcell.Value) Then
  If rcell.Value <> "" Then
   If IsNumeric(rcell.Value) = True Then
    MsgBox "It's a Number!"
   End If
  End If
 End If
Next rcell

End Sub

  https://stackoverflow.com/a/26911575/5079799

Dim i As Long, rng As Range

Set rng = GetUsedRange(ActiveSheet)

For i = rng.Cells.Count To 1 Step -1
 If Not IsError(rng(i).Value) Then
  If rng(i).Value <> "" Then
   If rng(i).Value = StringToCheck Then
    Debug.Print rng(i).Address
    rng(i).EntireRow.Delete
   End If
  End If
 End If
Next i

Note: I feel like I used this fine before, but it didn't work last time it gave me object after it deleted one row. 

https://stackoverflow.com/a/53355051/5079799

Public Sub ForEachRngBackwares()
Dim rcell As Variant, rng As Range

Set rng = GetUsedRange(ActiveSheet)

For Each rcell In ReverseRange(rng)
 If Not IsError(rcell.Value) Then
  If rcell.Value <> "" Then
   If IsNumeric(rcell.Value) = True Then
    Debug.Print rcell.Address
    rcell.entirerow.delete
   End If
  End If
 End If
Next rcell
End Sub
  • No labels