clean up code (if possible)....

jproffer

Well-known Member
Joined
Dec 15, 2004
Messages
2,647
Code:
If ActiveCell.Address = Range("A31").Address And ActiveCell.Value = "" Then
        UserForm1.ComboBox1.RowSource = "Lists!A1:A23"
        UserForm1.Show
    End If
    If ActiveCell.Address = Range("A32").Address And ActiveCell.Value = "" Then
        UserForm1.ComboBox1.RowSource = "Lists!A1:A23"
        UserForm1.Show
    End If
    If ActiveCell.Address = Range("A33").Address And ActiveCell.Value = "" Then
        UserForm1.ComboBox1.RowSource = "Lists!A1:A23"
        UserForm1.Show
    End If
    If ActiveCell.Address = Range("A34").Address And ActiveCell.Value = "" Then
        UserForm1.ComboBox1.RowSource = "Lists!A1:A23"
        UserForm1.Show
    End If
    If ActiveCell.Address = Range("A35").Address And ActiveCell.Value = "" Then
        UserForm1.ComboBox1.RowSource = "Lists!A1:A23"
        UserForm1.Show
    End If
    If ActiveCell.Address = Range("A36").Address And ActiveCell.Value = "" Then
        UserForm1.ComboBox1.RowSource = "Lists!A1:A23"
        UserForm1.Show
    End If
Is it possible to combine all these separate cells into an array or range of cells?

I've tried:
Code:
If ActiveCell.Address = Range("A31:A36").Address And ActiveCell.Value = "" Then

But no luck there.

Also, while we're at it. In this example, they are a continuous range (A31 thru A36). Is there a way to add more continuous but separate ranges to the same If statement?

For instance:
Code:
If ActiveCell.Address = Range("A31:A36, D4:D9, J56:J68").Address And ActiveCell.Value = "" Then

I'm (fairly) sure there is a much cleaner way to accomplish what's in the top code box here, but I just can't find the right syntax.

Thank you very much, in advance, for any help you can provide.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
For the first part, how about
Code:
   If Not Intersect(ActiveCell, Range("A31:A36")) Is Nothing Then
      UserForm1.ComboBox1.RowSource = "Lists!A1:A23"
      UserForm1.Show
    End If
 
Upvote 0
That just goes to show what a noob I am lol. That did it. Thank you to both of you for the coding and link. Worked perfectly.

And just for the sake of future searches, etc. As to the second part of my question, it is possible to string together several ranges into the same If statement. For instance:

Code:
If Not Intersect(ActiveCell, Range("A31:A36, D4:D8, J57:J75")) Is Nothing Then
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,492
Messages
6,125,115
Members
449,206
Latest member
burgsrus

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