I have some info. that looks like this:
Header Debit Credit aaaa 20 0 bbbb 0 60 cccc 30 0 xxxx 10 0 xxxx 0 40 xxxx 40 0 xxxx 0 10 oooo 500 0 oooo 0 52 oooo 0 500 pppp 10 pppp 0 10
(Note this starts in col. H)
The idea is that I want to go through this range, and where there are "blocks" of data (see the "xxxx" group), check for offsetting amounts.
I was able to put this together, to loop through the groups, but I'm not sure if it's the best way to do so. I'm afraid there will be a time it skips a line which is unintended - any ideas/tips on improving it?
Sub strike_out_Matching_Debit_and_Credits() Dim debitCol&, credCol&, lastRow&, startRow&, endRow&, i& Dim rng As Range, cel As Range Dim myWS As Worksheet Set myWS = Sheets("Raw - edited") With myWS debitCol = .Rows(1).Find(what:="Debit").column credCol = .Rows(1).Find(what:="Credit").column lastRow = .Cells(.Rows.Count, credCol).End(xlUp).row startRow = 2 For i = 2 To lastRow endRow = .Cells(i, debitCol).End(xlDown).row Set rng = .Range(.Cells(startRow, debitCol), .Cells(endRow, debitCol)) rng.Select If rng.Cells.Count - WorksheetFunction.CountA(rng) = 0 And rng.Cells.Count > 1 Then ' We now have a block to work through check_Values rng, rng.Offset(0, 1) check_for_Offset_Values rng, rng.Offset(0, 1) End If startRow = .Cells(endRow, debitCol).End(xlDown).row Next i End With End Sub
Thanks for any ideas/advice/tips!
Edit: I appreciate the help so far! I've made notes on the naming conventions, etc. Does anyone have any tips for tightening up the actual function of the code loop? That's what I'm mainly interested in.