'I am just trying to select all cells that fall within a certain range (>= 751 and <=1600) for 5 days. But I keep getting this Run-Time error "1004" Method "Range" of Object' _Global Failed. Any help is appreciated.
Public Sub tank_2()
Dim t As String
Dim var As Range
Set var = Application.InputBox("enter range", , , , , , , 8)
t = var.Address
For Each cell In Range(t)
If myrng = Empty And cell >= 751 And cell <= 1600 Then
myrng = cell.Address(0, 0)
ElseIf cell >= 751 And cell <= 1600 Then
myrng = myrng & "," & cell.Address(0, 0)
End If
Next cell
For Each cell In Range(t).Offset(0, 18)
If myrng = Empty And cell >= 751 And cell <= 1600 Then
myrng = cell.Address(0, 0)
ElseIf cell >= 751 And cell <= 1600 Then
myrng = myrng & "," & cell.Address(0, 0)
End If
Next cell
For Each cell In Range(t).Offset(0, 36)
If myrng = Empty And cell >= 751 And cell <= 1600 Then
myrng = cell.Address(0, 0)
ElseIf cell >= 751 And cell <= 1600 Then
myrng = myrng & "," & cell.Address(0, 0)
End If
Next cell
For Each cell In Range(t).Offset(0, 54)
If myrng = Empty And cell >= 751 And cell <= 1600 Then
myrng = cell.Address(0, 0)
ElseIf cell >= 751 And cell <= 1600 Then
myrng = myrng & "," & cell.Address(0, 0)
End If
Next cell
For Each cell In Range(t).Offset(0, 72)
If myrng = Empty And cell >= 751 And cell <= 1600 Then.
myrng = cell.Address(0, 0)
ElseIf cell >= 751 And cell <= 1600 Then
myrng = myrng & "," & cell.Address(0, 0)
End If
Next cell
Range(myrng).Select
End Sub
myrng
is neither declared nor has it anything assigned. It's not neccessary to read the address of a range and then convert it back to a range, you can useFor Each cell in var
. – FunThomas