screntropy
04-14-2010, 01:14 PM
I have large excel spreadsheets with address data and I am trying to create a macro that goes through one column (my "state" column) and determines if that value equals one of the values of my external text (tab-delimited) file (that contains the state abbreviations) and if it does not, then the entire row gets deleted.
Basically,
If [value in column] <> [value in states.txt]
Then delete row
I have some code that I have kind of pieced together, but I know it is SO wrong. Can you help me make it right?
Sub statesonly()
Dim states As String
Dim i As Long
states = "G:\Macros\states.txt"
For i = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
Debug.Print Cells(i, "J").Value
If (Cells(i, "J")) <> (states) Then
Cells(i, "J").EntireRow.Delete
End If
Next i
End Sub
Basically,
If [value in column] <> [value in states.txt]
Then delete row
I have some code that I have kind of pieced together, but I know it is SO wrong. Can you help me make it right?
Sub statesonly()
Dim states As String
Dim i As Long
states = "G:\Macros\states.txt"
For i = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
Debug.Print Cells(i, "J").Value
If (Cells(i, "J")) <> (states) Then
Cells(i, "J").EntireRow.Delete
End If
Next i
End Sub