2011gerry007
Member
I have a csv file that I need vba code to search through two specific columns row by row (I & J): and if an exact match found delete the entire row
So far I have long winded VBA that almost works, but unfortunately it only looks at one specific ie: column( J) at the moment, So what i need is for it to check two columns instead of one, so i need some help with tweaking by an expert and not an novice like myself
For instance
If Column (I2) = "john smith" & Column (J2) = "finance" ..then keep first instance of the entirerow and delete the rest of the rows below that that are contain the same value
but if the next row contains in Column (I3) = "mary smith" and Column(J3) = "finance"
and if a both column I2 = vbNullString & column I3vbNullString move on to next row
The below vba is what I have so far. any thoughts on a variation on this or even to get it run faster would be great ..many thanks in advance
Any help or thoughts on this would be a great help
__________________________________________________________________
So far I have long winded VBA that almost works, but unfortunately it only looks at one specific ie: column( J) at the moment, So what i need is for it to check two columns instead of one, so i need some help with tweaking by an expert and not an novice like myself
For instance
If Column (I2) = "john smith" & Column (J2) = "finance" ..then keep first instance of the entirerow and delete the rest of the rows below that that are contain the same value
but if the next row contains in Column (I3) = "mary smith" and Column(J3) = "finance"
and if a both column I2 = vbNullString & column I3vbNullString move on to next row
The below vba is what I have so far. any thoughts on a variation on this or even to get it run faster would be great ..many thanks in advance
Code:
Sub RemoveRepeatingStrings1()
Dim BaseStr As String, CurrStr As String
Dim EndRow As Long
Dim Iter As Integer
Dim next1 As Variant
EndRow = Range("A" & Rows.Count).End(xlUp).Row
BaseStr = Range("A1").Value
Application.ScreenUpdating = False
For Iter = 2 To EndRow
CurrStr = Range("j" & Iter).Value
If Range("J" & Iter).Value = vbNullString Then GoTo next1
If CurrStr = BaseStr Then
'Range("J" & Iter).Value = vbNullString
MsgBox Iter & " " & CurrStr
'Range("j" & Iter).EntireRow.Delete
Range("j" & Iter).EntireRow.ClearContents
'iter = iter - 1
next1: Else
BaseStr = Range("j" & Iter).Value
MsgBox Iter & " " & BaseStr
End If
Next Iter
Application.ScreenUpdating = True
Call DeleteBlankRows
End Sub
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Sub DeleteBlankRows()
Dim i As Long
Dim DelRange As Range
On Error GoTo Whoa
Application.ScreenUpdating = False
For i = 1 To 5000
If Application.WorksheetFunction.CountA(Range("A" & i & ":" & "Z" & i)) = 0 Then
If DelRange Is Nothing Then
Set DelRange = Rows(i)
Else
Set DelRange = Union(DelRange, Rows(i))
End If
End If
Next i
If Not DelRange Is Nothing Then DelRange.Delete shift:=xlUp
LetsContinue:
Application.ScreenUpdating = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume LetsContinue
End Sub
Any help or thoughts on this would be a great help
__________________________________________________________________
Mod edit : thread moved to appropriate forum !