ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Grab the right please (https://www.excelbanter.com/excel-programming/424922-grab-right-please.html)

Striker

Grab the right please
 
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



JLGWhiz

Grab the right please
 
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.

"Striker" wrote:

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





All times are GMT +1. The time now is 04:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com