exclude a range from another range

ww4612

Well-known Member
Joined
Apr 24, 2014
Messages
515
hello
i try to exclude one range from another range.
Code:
Sub ddt()
Dim fd As Range, a As Range
Set a = Range(Cells(1, 1), Cells(20, 10))
Set fd = Cells(7, 5)
Set a = a - fd
a.Value = 1
End Sub
i want to exclude range fd from range a. any solution?
 
You can put the values of the 'excluded' range into an array
Do whatever it is you're going to do to the whole range (including the excluded range)
Then put the values from the array back into the excluded range

Example
Rich (BB code):
Sub test()
Dim myrange As Variant
myrange = Range("B2:C3") 'Excluded Range
Range("A1:D4").Value = 1 'Whole Range
Range("B2:C3").Value = myrange
End Sub
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You can put the values of the 'excluded' range into an array
Do whatever it is you're going to do to the whole range (including the excluded range)
Then put the values from the array back into the excluded range

Example
Rich (BB code):
Sub test()
Dim myrange As Variant
myrange = Range("B2:C3") 'Excluded Range
Range("A1:D4").Value = 1 'Whole Range
Range("B2:C3").Value = myrange
End Sub
well. it seems that this is the only solution so far before the next version of VBA
 
Upvote 0
I wouldn't say it's the 'only' solution.
Other solutions have been posted.
And you've chosen not to use them (for valid reasons)

And I wouldn't count on the next version of VBA to inculde some function like that.
 
Upvote 0
You might also ask yourself this..

WHY is that range excluded?
What is it about that range that that is different from the rest of the range and made you decide it should be excluded?
Can that information be used somehow?
Perhaps by the AutoFilter
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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