Select multiple columns

diogodasilva

New Member
Joined
Feb 17, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi experts,

I am trying to edit this code so the target.column looks for multiple columns change instead of just one.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo Handler
If Target.Column = 8 And Target.Value <> "" Then
Application.EnableEvents = False
Target.Offset(0, 1) = Format(Now(), "dd-mm-yyyy hh:mm:ss")
Application.EnableEvents = True
End If
Handler:
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     Range("I3").Sort Key1:=Range("I4"), Order1:=xlDescending, Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Basically first part of the code is to update column 8 with a timestamp if any columns (1 to 17, except 8) is edited. and second part of the code reorganizes descending based on the timestamp.
 
Upvote 0
You're code is currently putting the date into column 9 if col 8 is changed. Are you saying you now want the date in col 8?
 
Upvote 0
You're code is currently putting the date into column 9 if col 8 is changed. Are you saying you now want the date in col 8?
Sorry, mistype.
first part of the code is to update column 9 with a timestamp if any columns (1 to 17, except 9) is edited. and second part of the code reorganizes descending based on the timestamp (column 9).
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   Select Case Target.Column
      Case 1 To 8, 10 To 17
         Range("I" & Target.Row).Value = Format(Now, "dd-mm-yyyy hh:mm:ss")
   End Select
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   Select Case Target.Column
      Case 1 To 8, 10 To 17
         Range("I" & Target.Row).Value = Format(Now, "dd-mm-yyyy hh:mm:ss")
   End Select
End Sub
Perfect!
Thank you .
One more thing. how could I auto sort column 9 (descending) automatically upon update?
 
Upvote 0
As that is a totally different question, it needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,597
Members
449,038
Latest member
Arbind kumar

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