ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba code to find ssn and move two columns (https://www.excelbanter.com/excel-programming/294750-vba-code-find-ssn-move-two-columns.html)

rozb

vba code to find ssn and move two columns
 
Hi
I need help! Any assistance helpful
I am trying to vba code in xl 97 a simple way to move through two columns "C" example below and "D" and if the active cell value is equal to a social security number then move the selection row , col c or col d over two columns to "E"
any suggestions

Dim Rng As Rang
FindString = "-" 'shortcut to 000-000-00
Set Rng = Range("c:c").Find(What:=FindString, LookAt:=xlPart
While Not (Rng Is Nothing
Range(ActiveCell, ActiveCell.End(xlToRight)).Selec
Set Rng = Range("c" & Rng.Row + 1 & ":c" & Rows.Count)
.Find(What:=FindString, LookAt:=xlPart
Wend

rozb

vba code to find ssn and move two columns
 
is there a way to search or find a ssn using vba code

is there a way to move row data (ie cells(0, 3:15) over two columns and then go to the next row and search for a ssn

SSN is formatted "000-00-000"

any assistance helpful

Thanks
Rozb

Dave Peterson[_3_]

vba code to find ssn and move two columns
 
This loops from C1 to the last used row in column C. (Change it to D if that
column is longer!)

Option Explicit
Sub testme()

Dim Rng As Range
Dim iCol As Long

With ActiveSheet
For Each Rng In .Range("c1:c" _
& .Cells(.Rows.Count, "C").End(xlUp).Row).Cells
For iCol = 0 To 1
If InStr(1, Rng.Offset(0, iCol).Text, _
"-", vbTextCompare) 0 Then
With Rng.Offset(0, 2 + iCol)
.Value = Rng.Offset(0, iCol).Value
.NumberFormat = Rng.Offset(0, iCol).NumberFormat
End With
Rng.Offset(0, iCol).ClearContents
End If
Next iCol
Next Rng
End With
End Sub

rozb wrote:

Hi,
I need help! Any assistance helpful!
I am trying to vba code in xl 97 a simple way to move through two columns "C" example below and "D" and if the active cell value is equal to a social security number then move the selection row , col c or col d over two columns to "E".
any suggestions?

Dim Rng As Range
FindString = "-" 'shortcut to 000-000-000
Set Rng = Range("c:c").Find(What:=FindString, LookAt:=xlPart)
While Not (Rng Is Nothing)
Range(ActiveCell, ActiveCell.End(xlToRight)).Select
Set Rng = Range("c" & Rng.Row + 1 & ":c" & Rows.Count) _
.Find(What:=FindString, LookAt:=xlPart)
Wend


--

Dave Peterson



All times are GMT +1. The time now is 12:14 PM.

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