[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 116
  • Last Modified:

Using a Range Name in a Macro

I have a Macro that has the following line it it.  I also have a Range Name named CustomerData that is composed of A7:B50.

Macro line of code:

        ActiveSheet.Range("$A$7:$B$50").AutoFilter field:=1, Criteria1:=Left(regionArray(iNextReg), 2)
    End If

End Sub


For this line of code, I'd like to make it so that if I change the size of the range (i.e. by adding another line or two), that the Macro performs against the range and not the A7:B50.  How do I code that?

Thank you,

B.
0
Bright01
Asked:
Bright01
  • 4
  • 3
  • 2
  • +1
1 Solution
 
MacroShadowCommented:
ActiveSheet.Range(NameofRange).AutoFilter field:=1, Criteria1:=Left(regionArray(iNextReg), 2)
0
 
Bright01Author Commented:
Please elaborate a little more;  Is the Criteria1 because I have two columns or if they are all included already in the range name, may I simply refer to the range name?

Thank you,

B.
0
 
MacroShadowCommented:
If you have a dynamic named range, which I imagine you do, instead of hard-coding the range you can use the named range as I showed in the previous post. It will relate to to the entire named range.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Rory ArchibaldCommented:
(not for points)
When using an autofilter, you can specify one or two criteria per column. Since you only specify one here, you only see criteria1. It has nothing to do with the size of the range you are filtering.
So
ActiveSheet.Range("CustomerData").AutoFilter field:=1, Criteria1:="some value"

Open in new window


means only show values in the CustomerData range where the first column equals "some value".
0
 
QlemoC++ DeveloperCommented:
You can also just use the range name in square brackets:
[CustomerData].AutoFilter field:=1, Criteria1:=Left(regionArray(iNextReg), 2)

Open in new window

0
 
Rory ArchibaldCommented:
As long as you don't have a variable in scope called CustomerData. ;)
0
 
Bright01Author Commented:
I'm in the presence of great minds!  

So in Microshadow's example for me; what does the Criteria here specify?

ActiveSheet.Range(NameofRange).AutoFilter field:=1, Criteria1:=Left(regionArray(iNextReg), 2)

?
0
 
Bright01Author Commented:
Sorry, it wasn't Microshadow's Criteria, it was what I copied for him to look at.  Still would like to know what it means.

B.
0
 
MacroShadowCommented:
Hard to tell without seeing the actual file.

Basically, its the two left-most characters of the iNextReg element of the regionArray array.
0
 
Bright01Author Commented:
Thank you Microshadow!  Very helpful.  I will be authoring more questions on the particular application since I'm still learning to build it.

Thanks again,

B.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now