VBA targeting only 2 columns

paul w

Board Regular
Joined
Apr 25, 2010
Messages
195
help required
Im using this code to insert a colon into a set of 4 numbers, and it works great but i only want it to check and change two columns, at the moment it checks and changes the whole sheet, how do i edit the code to only check colums 8 and 9.

Private Sub Worksheet_Change(ByVal Target As Range)
userinput = Target.Value
If userinput > 1 Then
newinput = Left(userinput, Len(userinput) - 2) & ":" & Right(userinput, 2)
Application.EnableEvents = False
Target = newinput
Application.EnableEvents = True
End If
End Sub
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try this as the first line:

Code:
If Target.Column < 8 Or Target.Column > 9 Then Exit Sub
 

paul w

Board Regular
Joined
Apr 25, 2010
Messages
195
thanks that worked i had been trying to mess with it (only way to learn i suppose) but couldnt get my head round it.
paul
 

Watch MrExcel Video

Forum statistics

Threads
1,108,911
Messages
5,525,593
Members
409,653
Latest member
rishir

This Week's Hot Topics

Top