Return Right 4 Digits, Including Preceding Zeroes

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I'm trying to get the last 4 digits from a text box, to populate a worksheet. The issue is, when there are preceding zeroes in the 4 digits, they're not coming over. Example, if the text box has 1230456, I'm only getting 456 to come over. I need to get the 0456 to come over. I tried these snippets, but they don't return the desired results.

Code:
 flpws4.Range("H" & flpLastRow4 + 1).Value = Format(Right(Me.cobo_AcctNum, 4), "####")
    flpws4.Range("H" & flpLastRow4 + 1).Value = Right(Me.cobo_AcctNum, 4)
Thoughts?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I'm trying to get the last 4 digits from a text box, to populate a worksheet. The issue is, when there are preceding zeroes in the 4 digits, they're not coming over. Example, if the text box has 1230456, I'm only getting 456 to come over. I need to get the 0456 to come over. I tried these snippets, but they don't return the desired results.

Code:
 flpws4.Range("H" & flpLastRow4 + 1).Value = Format(Right(Me.cobo_AcctNum, 4), "####")
    [B][COLOR="#FF0000"]flpws4.Range("H" & flpLastRow4 + 1).NumberFormat = "@"[/COLOR][/B]
    flpws4.Range("H" & flpLastRow4 + 1).Value = Right(Me.cobo_AcctNum, 4)
Thoughts?
Try adding what I show in red above.
 
Upvote 0
Thank you @Rick Rothstein! That worked. I wasn't even aware I could have duplicate lines for the same field without something like an IF statement.
 
Upvote 0

Forum statistics

Threads
1,225,635
Messages
6,186,125
Members
453,340
Latest member
Stu61

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