#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 152
Default VB Right

I need a fix to select only the 4 right digits in cells that are not empty in
a column (Range J2:??)

Thanks -- Suz

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default VB Right

I need a fix to select only the 4 right digits in cells that are not
empty in a column (Range J2:??)


I'm not entirely clear on the meaning of "fix" and "select" as you used them
in your question. This formula...

=RIGHT(J2,4)

will return up to the right-most 4 characters (that is, from zero to four
characters depending on the cell's content) in a cell (J2 for the above
example usage) and can be copied down to handle the other cells in the
column. Is that what you are looking for?

Rick

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default VB Right

Sub fix_ColumnJ()

LastRow = Cells(Rows.Count, "J").End(xlUp).Row
For RowCount = 2 To LastRow
data = Trim(Range("J" & RowCount))
'get last four didgits of text
If Len(data) = 4 Then
data = Trim(Right(data, 4))
End If
'convert to number if necessary
'comment out if not necessary
If IsNumeric(data) Then
Number = Val(data)
End If
Range("J" & RowCount) = Number
Next RowCount
End Sub

"Rick Rothstein (MVP - VB)" wrote:

I need a fix to select only the 4 right digits in cells that are not
empty in a column (Range J2:??)


I'm not entirely clear on the meaning of "fix" and "select" as you used them
in your question. This formula...

=RIGHT(J2,4)

will return up to the right-most 4 characters (that is, from zero to four
characters depending on the cell's content) in a cell (J2 for the above
example usage) and can be copied down to handle the other cells in the
column. Is that what you are looking for?

Rick


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



All times are GMT +1. The time now is 03:29 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"