A Simple Range Resize Operation

  • I was just trying to teach myself the resize operation. Instead I got a Compile Error: Invalid use of Property error. I don't understand why, it is a simple piece of code from my own insight. I simply want to add one row to the range. I'll admit that I wanted to add the row above the existing range not below it. I also don't know how to code that into what I'm trying to do. Thanks.


    Code
    Public Sub UsingResize()
     Dim G As Range
     Dim i As Integer
     Set G = Range("K4:M12")
     i = G.Rows.Count
         G.Resize (i + 1)
         G.Select
    End Sub
  • Re: A Simple Range Resize Operation


    Try this. :cool:

    Code
    Public Sub UsingResize()
    Dim G As Range
    Dim i As Integer
    Set G = Range("K4:M12")
    Set G = G.Offset(-1).Resize(G.Rows.Count + 1, G.Columns.Count)
    G.Select
    End Sub


    Another possibility. :cool:

    Code
    Public Sub UsingResize()
    Dim G As Range
    With Range("K4:M12")
        Set G = .Offset(-1).Resize(.Rows.Count + 1, .Columns.Count)
    End With
    G.Select
    End Sub
  • Re: A Simple Range Resize Operation


    Thank you! They work a treat, no more error. I really appreciate people like you taking the time out to help others like me. This has answered my question.
    Much appreciated.
    Dave

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!