Grab the right please

S

Striker

I have a column with numbers in it, as long as 15 in length. I want to grab
just the right two and add them to a variable, then move to the next record
and do the same.

The number is in column "K"

It's been many years since i worked with VBA, and 2007 seems a new animal.
Since the number in column K can be 10 or up to 15 in length, what Can I use
to grab the right two numbers in the string? Here is what I have so far,
just need to grab column "K" right two numbers and add them to a variable
counter if 01 add to this counter, if 02 add to this counter etc. Can only
go be one of 20 combinations of 01 - 20.

BTW Column K is formatted as a string.

Sub CountThese()

Dim lLastRow As Long

Dim rRange, rCell As Range

Dim iNum As Integer

lLastRow = Cells(Rows.Count, "A").End(xlUp).Row

txtRecordCount = lLastRow

Set rRange = Range("K2" & lLastRow)

For Each rCell In rRange.Cells



End Sub
 
J

JLGWhiz

In the simplest form:

myVar = Right(Range("K2").Value, 2)

If k2 contained the value "ABC123" then myVar would equal 23.
I am not sure how the leading zero might act. I know that Excel will
probably try to eliminate it if you put it on a sheet, so you will need to
check your results to make sure you are getting what you want. It could
require making everything text to keep the leading zero.
 

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