Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to grab a reference into VB | Excel Programming | |||
grab detail when = 1 | Excel Worksheet Functions | |||
Grab Parents? | Excel Programming | |||
Grab name of folder | Excel Programming | |||
Grab Password Name | Excel Programming |