Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to grab a reference into VB sb1920alk Excel Programming 2 March 4th 08 05:08 AM
grab detail when = 1 jenn Excel Worksheet Functions 0 January 12th 06 09:06 PM
Grab Parents? Kidaz Excel Programming 1 October 21st 05 07:04 PM
Grab name of folder scantor145[_13_] Excel Programming 1 July 1st 05 01:17 PM
Grab Password Name Paul P[_3_] Excel Programming 3 October 24th 03 01:07 AM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"