Left Function in VB

G

Guest

How to i code in VB the Left Function. The user will enter a six character
string in the first column and i need the second column to populate with the
first three characters of the first column.

Example
Column 1 Column 2
ABC100 ABC

If i coded it in the worksheet cell B1 , it would be =Left(A1,3), but i want
to put in VB as a Worksheet change. Is this possible?

Thanks

Nathaniel W. Polky

=Left(a
 
B

Bob Phillips

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:H10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Offset(0, 1).Value = Left(.Value, 3)
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top