ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Right (https://www.excelbanter.com/excel-programming/402459-vbulletin-right.html)

Suzanne

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


Rick Rothstein \(MVP - VB\)

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


joel

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




All times are GMT +1. The time now is 09:35 PM.

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