Dr. Demento
Well-known Member
- Joined
- Nov 2, 2010
- Messages
- 618
- Office Version
- 2019
- 2016
- Platform
- Windows
Can someone help me understand why the code below keeps adding one extra line of data (000000000) to the bottom of my dataset every time it's run and what I need to do to stop it?
Thanks, y'all!
Thanks, y'all!
Code:
With ActiveSheet
.UsedRange ' ~ Reset used range
Set rngUsed = rng_ActualUsed() ' ~~ determine actual used range in each sheet
Set rngX = Range("A1:" & Cells(1, rngUsed.Columns.Count).Address) ' ~~ Set for range of header row | cells function gives the last cell in row 1
For Each cell In rngX
With cell
Select Case True
Case .value Like "SSN"
For Each cellx In Intersect(cell.EntireColumn, rngUsed).Offset(1, 0) ' ~~ confines column of corresponding header
cellx = WorksheetFunction.Substitute(cellx, "-", vbNullString) ' remove dashes
cellx.NumberFormat = "@" ' Format as text -- REQUIRED!!
cellx = Application.Text(cellx, "000000000") ' format as text but retain leading zeros
Next cellx
End Select
End With
Next cell
End With