Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Using RIGHT function to get right-most digit for each cell in acolumn

Without looping, in VBA, how would I take each numeric value in column
A and change it's value to get only the right-most digit?
Thanks,
Sheldon
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using RIGHT function to get right-most digit for each cell in a column

If all your values in the column are numeric, then you probably want this...

=--RIGHT(A1)

If there can be non-numeric data in your columns, then you probably want
this instead...

=IF(ISNUMBER(A1),--RIGHT(A1),"")

Rick


"Sheldon Potolsky" wrote in message
...
Without looping, in VBA, how would I take each numeric value in column
A and change it's value to get only the right-most digit?
Thanks,
Sheldon


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Using RIGHT function to get right-most digit for each cell in acolumn

Rick, I tried what you suggested but preceded it with the line
Columns("A:A").Select
in my VBA code
I then typed in
=--RIGHT(A1)
but that line gave me a compile error so I must be missing something -
Expected: Line number or label or statement or end of statement

I never saw the -- syntax before so perhaps I'm using it incorrectly?

Thanks, Sheldon


=--RIGHT(A1)

If there can be non-numeric data in your columns, then you probably want
this instead...

=IF(ISNUMBER(A1),--RIGHT(A1),"")

Rick

"Sheldon Potolsky" wrote in message

...



Without looping, in VBA, how would I take each numeric value in column
A and change it's value to get only the right-most digit?
Thanks,
Sheldon- Hide quoted text -


- Hide quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,582
Default Using RIGHT function to get right-most digit for each cell in a column

Rick was giving you worksheet formulas, not VBA formulas.

Why do you not want to loop?

You could read the range into a variant array, process the contents of the
array (looping, of course), then dump the array back into the sheet.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Sheldon Potolsky" wrote in message
...
Rick, I tried what you suggested but preceded it with the line
Columns("A:A").Select
in my VBA code
I then typed in
=--RIGHT(A1)
but that line gave me a compile error so I must be missing something -
Expected: Line number or label or statement or end of statement

I never saw the -- syntax before so perhaps I'm using it incorrectly?

Thanks, Sheldon


=--RIGHT(A1)

If there can be non-numeric data in your columns, then you probably want
this instead...

=IF(ISNUMBER(A1),--RIGHT(A1),"")

Rick

"Sheldon Potolsky" wrote in message

...



Without looping, in VBA, how would I take each numeric value in column
A and change it's value to get only the right-most digit?
Thanks,
Sheldon- Hide quoted text -


- Hide quoted text -




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using RIGHT function to get right-most digit for each cell in a column

Actually, that line I gave you was a worksheet formula and not VBA code.
Just put the formula in Row 1 of the column you want the right-most digit in
and copy it down. If you still want to do it via VBA code, then you will
have to loop through all the rows handling each value individually... I
can't think of any other way to do it except through looping. I'm not sure
what you have against looping, but here is an example for you to consider...

Sub GetRightmostDigit()
Dim X As Long
Dim LastRow As Long
Const SourceColumn As String = "A"
Const DestinationColumn As String = "B"
With Worksheets("Sheet2")
LastRow = .Cells(.Rows.Count, SourceColumn).End(xlUp).Row
For X = 1 To LastRow
If IsNumeric(.Cells(X, SourceColumn).Value) Then
.Cells(X, DestinationColumn).Value = _
Right(.Cells(X, SourceColumn).Value, 1)
End If
Next
End With
End Sub

Rick


"Sheldon Potolsky" wrote in message
...
Rick, I tried what you suggested but preceded it with the line
Columns("A:A").Select
in my VBA code
I then typed in
=--RIGHT(A1)
but that line gave me a compile error so I must be missing something -
Expected: Line number or label or statement or end of statement

I never saw the -- syntax before so perhaps I'm using it incorrectly?

Thanks, Sheldon


=--RIGHT(A1)

If there can be non-numeric data in your columns, then you probably want
this instead...

=IF(ISNUMBER(A1),--RIGHT(A1),"")

Rick

"Sheldon Potolsky" wrote in message

...



Without looping, in VBA, how would I take each numeric value in column
A and change it's value to get only the right-most digit?
Thanks,
Sheldon- Hide quoted text -


- Hide quoted text -





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Using RIGHT function to get right-most digit for each cell in acolumn

Thanks Rick and Jon. Nothing against looping; I thought it could be
done without looping but I was mistaken so that's the way I'll do it
then. Thanks for the suggestions/code.
Sheldon

On Apr 21, 4:42*pm, "Rick Rothstein \(MVP - VB\)"
wrote:
Actually, that line I gave you was a worksheet formula and not VBA code.
Just put the formula in Row 1 of the column you want the right-most digit in
and copy it down. If you still want to do it via VBA code, then you will
have to loop through all the rows handling each value individually... I
can't think of any other way to do it except through looping. I'm not sure
what you have against looping, but here is an example for you to consider....

Sub GetRightmostDigit()
* Dim X As Long
* Dim LastRow As Long
* Const SourceColumn As String = "A"
* Const DestinationColumn As String = "B"
* With Worksheets("Sheet2")
* * LastRow = .Cells(.Rows.Count, SourceColumn).End(xlUp).Row
* * For X = 1 To LastRow
* * * If IsNumeric(.Cells(X, SourceColumn).Value) Then
* * * * .Cells(X, DestinationColumn).Value = _
* * * * * * * * * * * * * * * *Right(.Cells(X, SourceColumn).Value, 1)
* * * End If
* * Next
* End With
End Sub

Rick

"Sheldon Potolsky" wrote in message

...



Rick, I tried what you suggested but preceded it with the line
Columns("A:A").Select
in my VBA code
I then typed in
=--RIGHT(A1)
but that line gave me a compile error so I must be missing something -
Expected: Line number or label or statement or end of statement


I never saw the -- syntax before so perhaps I'm using it incorrectly?


Thanks, Sheldon


=--RIGHT(A1)


If there can be non-numeric data in your columns, then you probably want
this instead...


=IF(ISNUMBER(A1),--RIGHT(A1),"")


Rick


"Sheldon Potolsky" wrote in message


...


Without looping, in VBA, how would I take each numeric value in column
A and change it's value to get only the right-most digit?
Thanks,
Sheldon- Hide quoted text -


- Hide quoted text -- Hide quoted text -


- Hide quoted text -


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
conditional format on first & last digit on 3 digit cell data caprey New Users to Excel 3 December 17th 08 05:24 PM
validating data in acolumn delmac Excel Programming 2 May 15th 06 05:42 PM
Color a single digit in a mult-digit number cell Phyllis Excel Discussion (Misc queries) 6 November 17th 05 12:46 AM
avoid retype the number more than one time withen acolumn This no. already exist Excel Discussion (Misc queries) 1 April 4th 05 10:25 AM
16 DIGIT NUMBERS IN CELL WITHOUT LAST DIGIT BEING A ZERO jnkell Excel Worksheet Functions 2 December 18th 04 07:13 PM


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

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

About Us

"It's about Microsoft Excel"