Function arguments

timlh42

Board Regular
Joined
Sep 27, 2017
Messages
76
I have the following


If Not Intersect(Target, Range("H7:H37, I7:I37, N7:N37, O7:O37")) Is Nothing Then
If Target.Count > 1 Then Exit Sub

As in the above example, the range of cells will continue to be 2 columns and then skip 4 columns, 2 columns and then skip 4 columns, etc. This pattern will continue for 180 times.

Is there any way to do this without physically typing in every range in the argument?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi

If I unserstand correctly you have 180 groups of 6 columns for which you are intersted in the first 2 columns of each group.

The columns are 8:1087(13+179*6)
The rows you want are 7:37


One options is:

Code:
If Target.Row < 7 Or Target.Row > 37 Then Exit Sub
If Target.Column < 8 Or Target.Column > 1087 Then Exit Sub
If (Target.Column - 8) Mod 6 > 1 Then Exit Sub
If Target.Count > 1 Then Exit Sub

or, you can combine them:

Code:
If (Target.Row < 7 Or Target.Row > 37) Or (Target.Column < 8 Or Target.Column > 1087) Or _
   ((Target.Column - 8) Mod 6 > 1) Or (Target.Count > 1) Then Exit Sub
 
Upvote 0
One more quick question. Is there a way to add another argument to the above?

I would like to have column H and every 6th column afterward call the userform if the value is greater than 2
 
Upvote 0
Hi

Not sure I understand correctly, check this that covers both cases

Code:
If Target.Row < 7 Or Target.Row > 37 Then Exit Sub
If Target.Column < 8 Or Target.Column > 1087 Then Exit Sub
If Target.Count > 1 Then Exit Sub


If (Target.Column - 8) Mod 6 <= 1 Then

    ' code for first case, first 2 columns out of each group of 6

End If


If (Target.Column - 8) Mod 6 = 0 Then

       ' code for second case, first column out of each group of 6

End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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