Intersect - Variable Range - Error

meledward23

New Member
Joined
Aug 2, 2016
Messages
19
So I am using intersect to clearcontents, as shown below. I am getting an "Object variable or with block variable not set" and I am stuck.
If I manually enter the resulting Range name (option2x) instead of the variable range name (rngselect), then it works.

Dim rngselect As Range
Dim lrow As Long
Dim rng As Range

Set rngselect = Range("assemselect") 'user selected range result on demo is "OPTION2X"

'show only user selected range
lrow = Sheets("HS Template").Range("ag" & Rows.Count).End(xlUp).Row
Range("ag1:ag" & lrow).EntireRow.Hidden = True
Range("a1:a5").EntireRow.Hidden = False
Range(rngselect).EntireRow.Hidden = False

'clear manual data in range
msgbox rngselect 'results in "option2x"
Application.Intersect(rngselect, Range("c:c")).clearcontents 'if I use application.intersect("Option2x",range("c:c")).clearcontents this works

Application.GoTo ActiveSheet.Range("A1"), True
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Are you on the "HS Template" sheet when you run the code?
 
Upvote 0
Personally I would be expecting
VBA Code:
Range(rngselect).EntireRow.Hidden = False
to error first with a 1004 error
 
Upvote 0
What is the range of Range("assemselect")?
 
Upvote 0
Personally I would be expecting
VBA Code:
Range(rngselect).EntireRow.Hidden = False
to error first with a 1004 error

Works fine.
1596651063792.png
 
Upvote 0
Assemselect is a dropdown, where the user selects Option1x, Option2x, etc to option 39x.
Option1x = a range of say row 3:14,
option 2x = a range of say row 21:32

I have also tried running it where
Option1Y = a range of A3:a14
Option2Y = a range of a21:a32

Which worked fine in the top half. But those dont work with the intersect, so I am now running option#x
 
Upvote 0
Option1x = a range of say row 3:14,
option 2x = a range of say row 21:32

If that is the case why do you need to use EntireRow in the below?
VBA Code:
Range(rngselect).EntireRow.Hidden = False

Asking because you get an Error 91 when the ranges don't intersect.

What does
VBA Code:
MsgBox rngselect.address
give you?

P.S. I can't see any code line highlighted yellow in your image, have you debugged it?
 
Upvote 0
FALSE INFO REMOVED.
 

Attachments

  • 1596651753731.png
    1596651753731.png
    26.8 KB · Views: 4
  • 1596651871761.png
    1596651871761.png
    26.8 KB · Views: 5
Last edited:
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,930
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