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!!!
 
Try:

Code:
With Union(Found.Offset(0, -1), Found.Offset(0, 1).Resize(, 2))
    .Copy Destination:=Range("C" & Rows.Count).End(xlUp).Offset(1)
    .ClearContents
End With
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Thanks a lot for your reply! The code reads like it should work fine, yet it seems to be constantly looping still (freezing my Excel).

So, this is how it looks now:
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
With Union(Found.Offset(0, -1), Found.Offset(0, 1).Resize(, 2))
.Copy Destination:=Range("C" & Rows.Count).End(xlUp).Offset(1)
.ClearContents
End With
Set Found = .FindNext
Loop Until Found Is Nothing
End If
End With
 
Upvote 0
You are not clearing the found cell, so naturally you will keep finding it...
 
Upvote 0
I got it working now, using the following changes. :)

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
            With Union(Found.Offset(0, -1), Found.Offset(0, 1).Resize(, 2))
                .Copy Destination:=Range("C" & Rows.Count).End(xlUp).Offset(1)
                Found.Offset(0, -1).Resize(, 4).ClearContents
            End With
            
                Set Found = .FindNext
            Loop Until Found Is Nothing
        End If
    End With

Thanks for all the help!
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,933
Members
449,480
Latest member
yesitisasport

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