How to let VBA code work over entire column?

firexcelsior

New Member
Joined
Aug 11, 2021
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Hello ?

I have a VBA code which allows for multiple selections from a drop down list:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$I$3" Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub


The code works just fine but my only problem is that it only runs on one cell (Cell I3).

What should I change in Target.Address = "$I$3" to make it run over the entire table column (from I3 to I1639)?

Thank you!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,855
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
replace this row:
VBA Code:
If Target.Address = "$I$3" Then
with these two:
VBA Code:
    Const rngA = "I3:I1639"
    If Not Intersect(Target, Target.Parent.Range(rngA)) Is Nothing Then
 
Solution

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
3,789
Office Version
  1. 365
Platform
  1. Windows
Try replacing this:
VBA Code:
If Target.Address = "$I$3" Then

with this:
VBA Code:
If Target.Cells.CountLarge > 1 Then GoTo Exitsub
    If Not Intersect(Target, Range("I1:I1639")) Is Nothing Then
 

firexcelsior

New Member
Joined
Aug 11, 2021
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
replace this row:
VBA Code:
If Target.Address = "$I$3" Then
with these two:
VBA Code:
    Const rngA = "I3:I1639"
    If Not Intersect(Target, Target.Parent.Range(rngA)) Is Nothing Then
Thanks, works perfectly!
 

bobsan42

Well-known Member
Joined
Jul 14, 2010
Messages
1,855
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
glad we could help (y)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,309
Messages
5,836,574
Members
430,438
Latest member
David Gr

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
Top