repeat Worksheet_Change event on various colums

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
337
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,224,590
Messages
6,179,754
Members
452,940
Latest member
rootytrip

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