T
Trudye
Hi Guys, I am trying to delete all the rows preceeding the FIRST ro
that has 'o1CR' in the first 4 bytes of col 'A'. The very first ro
contains a hdr with the literal "AccountNumber" in cell A1.
I have managed to locate the 01CR rec and realize the correct ro
number to start my deletes moving from bottom (the 01CR rec ) to th
top (which I am told is the best way to delete in Excel).
However I have not been successful in assigning the row that proced
the 01CR row as the LastRow. Does anyone know how I do that?
Here is my code. I know there are better techniques but Excel is not m
first language.
Sub CleanUp_File_2()
Dim i As Integer
Dim MaxElements As Integer
Dim cnt As Integer
Dim LeftValue As String
Dim HDR As Range
Dim row1 As Variant
LeftValue = ""
cnt = 0
MaxElements = 7000
ActiveCell.Range("A2").Select
For i = 1 To MaxElements
LeftValue = Left(Cells(i, 1), 11)
If Left(Cells(i, 1), 4) = "01CR" Then
Exit For
Else
cnt = cnt + 1
End If
If cnt = 4379 Then
Stop
End If
Next i
Range("A2").Select
ActiveCell.FormulaR1C1 = "HDR"
Dim LastRow As Range
cnt = cnt - 1
row1 = ("A" & cnt)
LastRow = Worksheets("sheet1").Cells(cnt, 0)
For i = LastRow To HDR Step 1 - 1
If Cells(i, 0) = "AccountNumber" Then
Else
Rows(i).Delete
End If
Next i
End Sub
The error msg appication defines or object defined error becaus
.Cells(cnt, 0)
is invalid. How can I fix this
that has 'o1CR' in the first 4 bytes of col 'A'. The very first ro
contains a hdr with the literal "AccountNumber" in cell A1.
I have managed to locate the 01CR rec and realize the correct ro
number to start my deletes moving from bottom (the 01CR rec ) to th
top (which I am told is the best way to delete in Excel).
However I have not been successful in assigning the row that proced
the 01CR row as the LastRow. Does anyone know how I do that?
Here is my code. I know there are better techniques but Excel is not m
first language.
Sub CleanUp_File_2()
Dim i As Integer
Dim MaxElements As Integer
Dim cnt As Integer
Dim LeftValue As String
Dim HDR As Range
Dim row1 As Variant
LeftValue = ""
cnt = 0
MaxElements = 7000
ActiveCell.Range("A2").Select
For i = 1 To MaxElements
LeftValue = Left(Cells(i, 1), 11)
If Left(Cells(i, 1), 4) = "01CR" Then
Exit For
Else
cnt = cnt + 1
End If
If cnt = 4379 Then
Stop
End If
Next i
Range("A2").Select
ActiveCell.FormulaR1C1 = "HDR"
Dim LastRow As Range
cnt = cnt - 1
row1 = ("A" & cnt)
LastRow = Worksheets("sheet1").Cells(cnt, 0)
For i = LastRow To HDR Step 1 - 1
If Cells(i, 0) = "AccountNumber" Then
Else
Rows(i).Delete
End If
Next i
End Sub
The error msg appication defines or object defined error becaus
.Cells(cnt, 0)
is invalid. How can I fix this