Number of characters using VBA

drjpb

Board Regular
Joined
Dec 11, 2013
Messages
61
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Hi,
I want to convert values in a column to 12 characters from Right.
Normally we write a formula like =Right(F8,12), i want similar results using vba so i don't have to write a formula each time in a worksheet.

I have column F starting from F8, till end, which i would like to use vba to remove extra characters from left, leaving only 12 characters from Right.

F8
Desired Results (in F8)

<tbody>
</tbody>
283516

<tbody>
</tbody>
283516

<tbody>
</tbody>
283627

<tbody>
</tbody>
283627

<tbody>
</tbody>
283790

<tbody>
</tbody>
283790

<tbody>
</tbody>
820140000001430

<tbody>
</tbody>
140000001430

<tbody>
</tbody>
820140000001800

<tbody>
</tbody>
140000001800

<tbody>
</tbody>

<tbody>
</tbody>

I need the results on same location (F column).

Many Thanks.

<tbody>
</tbody>
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this:
Code:
Sub a928523()
Dim r As Range
For Each r In Range("F8", Cells(Rows.count, "F").End(xlUp))
r.Value = Right(r.Value, 12)
Next
End Sub
 
Upvote 0
Thanks Akuini, it worked well, except for the number of characters in results are 11, not 12. I know it's strange behavious, i checked the column, there is no extra space or any character. I am using Office 2013.
Anyhow changing code from 12 to 13 fixed my issue.

Thanking you once again for prompt solution.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top