Multiple Ifs Select

ManUBlueJay

Active Member
Joined
Aug 30, 2012
Messages
304
Office Version
  1. 2016
Platform
  1. Windows
I have a very complicated Question. The only way around that I can see is using 7 If,s
I am happy with a simple VBA formula or a way to name the ranges
I have seven different ranges, and depending on the users input I want to select given ranges.
If users selects Option 1 I want to select 7 ranges. A1:A4, A10:A14,A20:A24, A30:A34, A40:A44, A50:A54, A60:A64, A70:A74
If users selects Option 2 I want to select 6 ranges. All the options except the last.
If users selects Option 3 I want to select 5 ranges. All the options except the last2.

All the way up to user selecting option 7 and only A1:A4 would need selecting
I can't make a table and use a lookup.
Any help would be appreciated
 
See if this works
VBA Code:
Sub otherway()
Dim rng As Range, rng2 As Range, a As Long, c As Long
Set rng = Range("A1:A4, A10:A14,A20:A24, A30:A34, A40:A44, A50:A54, A60:A64, A70:A74")
c = rng.Areas.Count
a = Range("B1").Value + 1
If a <= c Then
    Set rng2 = rng.Areas(a)
    Do Until a = c
        a = a + 1
        Set rng2 = Application.Union(rng2, rng.Areas(a))
    Loop
    rng2.Select
End If
End Sub
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hmmm

VBA Code:
Dim optNum as Long
Dim FullRange as Range
Set FullRange = Range(""A1:A4, A10:A14,A20:A24, A30:A34, A40:A44, A50:A54, A60:A64, A70:A74")

optNum = Range("B1").Value

With FullRange
 
    Application.Intersect(.Cells, Range(.Cells(1,1), .Areas(optNum +1))).Select

End With
 
Upvote 0
VBA Code:
Dim optNum as Long Dim FullRange as Range Set FullRange = Range(""A1:A4, A10:A14,A20:A24, A30:A34, A40:A44, A50:A54, A60:A64, A70:A74") optNum = Range("B1").Value With FullRange Application.Intersect(.Cells, Range(.Cells(1,1), .Areas(optNum +1))).Select End With
Works Brilliant. Do you have a suggestion for Post 10 to now select the ranges the come after B1
 
Upvote 0
You still havn't explained what these ranges are being used for? Selecting discontinous ranges is probably not the best approach.
 
Upvote 0
Sorry I earlier posted I am reformatting them. So rest assured I am not going to use the select.
The format is complicated, I am only using you to show me how to select them, so I can finish with my code to finish the project.
Probably clear as mud but I was able to use what you posted for the first part
 
Upvote 0
The format is complicated
In your opinion. Like the method of applying it, I expect that you're over complicating it. With the quality of your questions you're only getting answers at best, not solutions.
 
Upvote 0

Forum statistics

Threads
1,215,540
Messages
6,125,409
Members
449,223
Latest member
Narrian

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