repeat Worksheet_Change event on various colums

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
327
Office Version
  1. 2016
Platform
  1. Windows
I have a worksheet with some 200 columns. These columns make 20 blocks of 10 columns, each block has the similar structure. The same Worksheet-Change event needs to be triggered on, say, column A, column K, col T, and so on.

I can do this as indicated here below, but I am looking for a more condensed way.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim kol_A_rng As Range
Dim kol_K_rng As Range
Dim kol_T_rng As Range

Set kol_A_rng = Range("A3:A300")
Set kol_K_rng = Range("K3:K300")
Set kol_T_rng = Range("T3:T300")

If Target.Count = 1 And Not Application.Intersect(Target, kol_A_rng) Is Nothing Then
    'do something  (this something is approx. 30 lines !)
ElseIf Target.Count = 1 And Not Application.Intersect(Target, kol_K_rng) Is Nothing Then
    'do the same thing as in col A
ElseIf Target.Count = 1 And Not Application.Intersect(Target, kol_T_rng) Is Nothing Then
    'do the same thing as in col A
'and so on

Else
End if

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi,
try following & see if does what you want

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng         As Range
    
    If Target.CountLarge > 1 Then Exit Sub
    
    ' range Areas
    Set rng = Me.Range("A3:A300,K3:K300,T3:T300")
    
    If Not Intersect(Target, rng) Is Nothing Then
        
        'do the same thing for all Areas
        
    End If
    
End Sub

Dave
 
Upvote 0
Solution
If you are working with each block of 10 columns, start from column A (col 1), column K (col 11),, column U (col 21):
PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
   if .row >=3 and .row <=300 and (.column mod 10)=0 then
     ---main code here-----
   end if
end with
End sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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