Results 1 to 3 of 3

Thread: Minimum range of variable

  1. #1
    New Member
    Join Date
    Jul 2019
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default 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. #2
    MrExcel MVP FormR's Avatar
    Join Date
    Aug 2011
    Location
    UK
    Posts
    6,089
    Post Thanks / Like
    Mentioned
    24 Post(s)
    Tagged
    2 Thread(s)

    Default 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
    Last edited by FormR; Aug 8th, 2019 at 03:13 AM.
    [code]your code[/code]

  3. #3
    New Member
    Join Date
    Jul 2019
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Minimum range of variable

    Quote Originally Posted by FormR View Post
    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

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •