Minimum range of variable

Finschken

New Member
Joined
Jul 29, 2019
Messages
5
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
 

FormR

MrExcel MVP
Joined
Aug 18, 2011
Messages
6,220
Office Version
365
Platform
Windows
Hi, how about testing the variables value before performing the clear - something like:

Rich (BB 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:

Rich (BB code):
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
LastRow = Application.Max(100, LastRow)
Range("R" & LastRow & ":" & "R100").Clear
 
Last edited:

Finschken

New Member
Joined
Jul 29, 2019
Messages
5
Hi, how about testing the variables value before performing the clear - something like:

Rich (BB 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:

Rich (BB 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
 

Forum statistics

Threads
1,082,621
Messages
5,366,623
Members
400,906
Latest member
incanus

Some videos you may like

This Week's Hot Topics

Top