VBA: How do I use negative range for the .Resize function?

h711

Board Regular
Joined
Jun 23, 2008
Messages
164
Range("C3").Resize(2,2)
covers C3,C4,D3,D4

But what if I want to still use C3 as reference point to cover B2, B3, C2, C3?
Range("C3").Rasize(-2,-2)
does NOT work and give error.

Any ideas? Thanks for the help!!!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Arguments in Resize method shoud be equal or greater than 1 (default value)
Offset first
Code:
Range("C3").Offset(,-1).Resize(2,2)
 
Upvote 0
cool, I know both offset and resize, but didn't thought about put them together.

I like this place, ppl always have all kinds of ideas to solve problems.

Thanks.
 
Upvote 0
I know this is an old thread, but i'm looking for a way to do something with the above code.

I use a piece of code with Resize( , ).Offset( , ) as well.

If i have a piece of code that would end in Cell B2 and i wanted to select A2, B2 and C2 i would use the following:

Offset(0, -1).Resize(1, 3).

But what would i have to use if i end in Cell B2 and i would want to select A2, C2 and D2? Is it possible to skip a cell in the selection?
 
Upvote 0
You would have to use Union too:
Code:
Union(offset(0, -1), offset(0, 1).resize(, 2))
 
Upvote 0
Hey,

Thanks a lot for your reply.
My question was regarding the following code i have:

Code:
    Dim Found As Range
 
    Const SrchCol As String = "H"
    Const SrchTxt As String = "GND"
 
    With Columns(SrchCol)
        Set Found = .Find(What:=SrchTxt, After:=.Cells(1, 1), _
            LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
        If Not Found Is Nothing Then
            Do
                Found.[B]Union(Offset(0, -1), Offset(0, 1).Resize(, 2)).[/B]Cut _
                    Destination:=Range("C" & Rows.Count).End(xlUp).Offset(1)
                Set Found = .FindNext
            Loop Until Found Is Nothing
        End If
    End With

But i get a Debug error now on that very line, when i try to run it.
Any suggestions? :)
 
Upvote 0
Code:
Sub CoolResize()
    Range("C3")(0, 0).Resize(2, 2).Select
End Sub
 
Upvote 0
More like:

Code:
Union(Found.Offset(0, -1), Found.Offset(0, 1).Resize(, 2))

Thanks, but appearantly the Cut command will not work this way.
If i use Copy instead my code will get stuck repeating itself (because the GND value it is looking for will never dissapear.

Would it be possible to do a Copy of the selected Cells, Paste them according to the code and then Delete the source cells before the repeat?
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top