# Thread: Minimum range of variable Thanks:  1 Post #5322152 (1) Likes:  1 Post #5322152 (1)

1. ## Minimum range of variable

Hello, I have a "variable" (I think its called), called LastRow. And LastRow will find the latest row with data in special column. But if LastRow is empty. It will cause problems and delete information. Can I in some way set a minimum LastRow range? All help would be awesome!

Code:
LastRow = .Cells(.Rows.count, "A").End(xlUp).Row
Range("R" & LastRow & ":" & "R100").Clear

2. ## Re: Minimum range of variable

Hi, how about testing the variables value before performing the clear - something like:

Code:
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
If LastRow > 100 Then
Range("R" & LastRow & ":" & "R100").Clear
End If
Or if you wanted to set it to a minimum value you could try something like:

Code:
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastRow = Application.Max(100, LastRow)
Range("R" & LastRow & ":" & "R100").Clear

3. ## Re: Minimum range of variable

Originally Posted by FormR
Hi, how about testing the variables value before performing the clear - something like:

Code:
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
If LastRow > 100 Then
Range("R" & LastRow & ":" & "R100").Clear
End If
Or if you wanted to set it to a minimum value you could try something like:

Code:
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastRow = Application.Max(100, LastRow)
Range("R" & LastRow & ":" & "R100").Clear
Woohoo, it works perfectly. Thanks alot for your help and your time! =D