Need VBA code with a function..

Jdog12

New Member
Joined
May 21, 2020
Messages
23
Office Version
  1. 365
Platform
  1. Windows
I have a report that i need to extract last 4 digits of social security numbers. I have been inserting a column (column C) next to the SS# column and I use the function "right(B4,4)" and go down the column.

I need VBA code which I can cycle through all the social security numbers and extract the last 4 digits of each.

Many thanks.

1627013475883.png
 

Attachments

  • 1627013387162.png
    1627013387162.png
    17.7 KB · Views: 3

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Give this macro a try...
VBA Code:
Sub SSN()
  Columns("C").Insert
  With Range("B4", Cells(Rows.Count, "B").End(xlUp))
    .Offset(, 1) = Evaluate("MOD(" & .Address & ",10000)")
    .Offset(, 1).NumberFormat = "0000"
  End With
End Sub
 
Upvote 0
Give this macro a try...
VBA Code:
Sub SSN()
  Columns("C").Insert
  With Range("B4", Cells(Rows.Count, "B").End(xlUp))
    .Offset(, 1) = Evaluate("MOD(" & .Address & ",10000)")
    .Offset(, 1).NumberFormat = "0000"
  End With
End Sub
I got this error #VALUE! when I ran it.
 
Upvote 0
Try this:

.Offset(, 1) = Evaluate("RIGHT(" & .Address & ",4)")
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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