Hey,
Hoping someone can help me.
I've been trying different stuff all morning and kind of have my code limping along.
What I'm trying to do is export an excel spreadsheet from another program. It fills it with junk, but a material description is always in column A and the qty is always in the same row of column B.
My idea is to find the last row, then loop through from A1 down to ALastRow. Check the first two letters of A? and if there don't match the (5) I'm looking for, then delete the row. Ideally, I would end up with a spread sheet, where each row has just the relevant info. Then I'll delete columns B and D-whatever. Sort by name and then add up the qty. That way, I can export this document with all the material we order from a vendor over a period of time, run this program, and end up with a spread sheet that shows each unique material once, and has the total qty of that material.
The below code now seems to work, but it goes "infinate loop" on me. I've even tried to put in breaks at 100,500,1000,1500,2000, and 2500 rows. I had code to pop up a message box and show me it had reached that point. It gets to the 100 msgbox, but not the 500. There were approximately 3300 rows in this sheet. I let it run for a while, but it never finished. The part that displayed did appear to have worked correctly.
Hoping someone can help me.
I've been trying different stuff all morning and kind of have my code limping along.
What I'm trying to do is export an excel spreadsheet from another program. It fills it with junk, but a material description is always in column A and the qty is always in the same row of column B.
My idea is to find the last row, then loop through from A1 down to ALastRow. Check the first two letters of A? and if there don't match the (5) I'm looking for, then delete the row. Ideally, I would end up with a spread sheet, where each row has just the relevant info. Then I'll delete columns B and D-whatever. Sort by name and then add up the qty. That way, I can export this document with all the material we order from a vendor over a period of time, run this program, and end up with a spread sheet that shows each unique material once, and has the total qty of that material.
The below code now seems to work, but it goes "infinate loop" on me. I've even tried to put in breaks at 100,500,1000,1500,2000, and 2500 rows. I had code to pop up a message box and show me it had reached that point. It gets to the 100 msgbox, but not the 500. There were approximately 3300 rows in this sheet. I let it run for a while, but it never finished. The part that displayed did appear to have worked correctly.
VBA Code:
Sub MaterialQty()
'find last row in worksheet
Call FindLastRow(LastRow)
test = ""
' MsgBox (LastRow)
'loop, in column A, from first cell to last cell.
For j = 1 To LastRow
'set "test" to cell value
test = Range("A" & j)
'check if cell value starts with any of these beginnings
If Left(test, 2) = "CR" _
Or Left(test, 2) = "HR" _
Or Left(test, 2) = "AL" _
Or Left(test, 2) = "GA" _
Or Left(test, 2) = "SS" Then
'Do nothing and skip to end if
Else
'if it's not equal, delete the row
Sheet1.Cells(j, 1).EntireRow.Delete
'deleting row bumps up all rows, subtract "1" to check that row again
j = j - 1
End If
Next
End Sub