Trying to solve for a loop that reads the account numbers in column 'E' on the "Info sheet" starting from 'E2' and takes that number and inputs it in the first row containing an empty white cell on the "Proof" sheet ('E4') under the account number section. Once the number is placed there, the "long name" (found in the table on the 200th row) associated with the account number in the cell 'E4' appears in the first empty white cell ('B4') under the account name section. Then, the loop continues and reads the next cell ('E3') on the "Input sheet", and if that account number belongs to the same name, place that number in the next white cell ('G4') on the "Proof" sheet. If the account number is not associated with the account name in cell 'B4', put it in the next line containing an empty white cell 'E12' and assign the appropriate name for that number in cell under account name in cell 'B12' and continue down the list in column 'E' on the Info sheet and repeat the process until all the account numbers on the first sheet are complete and all the appropriate account numbers are on the row that has the appropriate 'long name' for those account numbers.
How can I put all the accounts linked to the account name on the same row in the specific white cells without posting them twice on the same row?
This is the code I have:
Sub loopything()
Dim infoSheet As Worksheet, proofSheet As Worksheet, refRange As Range, lastRow As Long, r As Long
Dim acct As String, foundAcct As Range, nextRow As Long
Set infoSheet = ThisWorkbook.Sheets("Info Sheet")
Set proofSheet = ThisWorkbook.Sheets("Proof")
With proofSheet
nextRow = 4 ' waiting to adjust to normal table format
End With
With proofSheet
Set refRange = .Range("A200:L79000")
End with
With InfoSheet
lastRow = 30 ' .cells(.rows.count, "E").end(xlup).row
For r = 2 To lastRow
acct = .Cells(r, "E")
Set foundAcct = refRange.Find(what:=acct)
longname = foundAcct.Offset(0, 1)
proofSheet.Cells(nextRow, "E") = acct
proofSheet.Cells(nextRow, "B") = longname
nextRow = nextRow + 8 ' would be nicer to just add one row (see first note)
Next r
End With
End Sub
Take a look at the snippets for reference.
The code is currently doing this:
See how in the practice examples, which is supposed to mimic the real sheets, the name appears on multiple rows with their respective account numbers when they should be appearing on the same row under the same name with all the account numbers on one row.