Using the "Right" function correctly

Sara Hedtler
Sara Hedtler used Ask the Experts™
on
I have written the following code and its not working:

textbox 1:  txtVin    ~ This is where the values are written
textbox 2:  txtUnitDescription   ~ This is where the "right" code will be placing the last 4 of the vin number.

Sub LastVinNo()
    Dim vin As String
    txtVin
    vin = Right(txtVin, 4)
    txtUnitDescription = vin
End Sub

I have placed this in a macro and within the code of the form itself - neither are working.
How do I write the actual "Right" function on excel vba correctly?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Older than dirt
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Try this.

Sub LastVinNo()
    txtUnitDescription.Text = Right(txtVin.Text, 4)
End Sub

Open in new window

Sara HedtlerInsurance Director

Author

Commented:
Thank you so much Martin, this did it!
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Technically the ".Text" parts of the code are not necessary because 'Text' is the default property of a textbox, but I usually include it for self-documenting purposes. In any case you’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
              Experts Exchange Top Expert VBA (current)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial