Hey new to macros. My issue, I want my macro to loop through a number of cells on sheet1 and then transfer the entries into specific cells onto sheet2. On sheet2 column A, I want specific headings to be printed based on whether or not the values in sheetA1 are different.
Visual aid:
Sheet 1
How I would like data to copied into sheet 2:
How data gets copied into Sheet 2:
My code:
Currently the ENDTRNS line gets overwritten by the next set of SPL and TRNS in the loop. Is it possible to get it to insert a new line with ENDTRNS then continue?
Visual aid:
Sheet 1
Book2.xlsm | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | |||
1 | 3564 | INVOICE | 20656 | Acounts Receivable | 01/02/2022 | 98 | K.G Community Mart | Exp Charge | 10.62 | |||
2 | 3564 | INVOICE | 20656 | SlBakery | 01/02/2022 | 98 | K.G Community Mart | TOTAL SALES | 10.62 | |||
3 | 3566 | CREDIT MEMO | 20659 | Acounts Receivable | 01/02/2022 | 98 | K.G Community Mart | Exp Charge | -41.22 | |||
4 | 3566 | CREDIT MEMO | 20659 | SlBakery | 01/02/2022 | 98 | K.G Community Mart | TOTAL SALES | -41.22 | |||
5 | 3567 | CREDIT MEMO | 20660 | Acounts Receivable | 01/02/2022 | 98 | K.G Community Mart | Exp Charge | -55.25 | |||
6 | 3567 | CREDIT MEMO | 20660 | SlBakery | 01/02/2022 | 98 | K.G Community Mart | TOTAL SALES | -55.25 | |||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B1:B6 | B1 | =IF((J1<0),"CREDIT MEMO",IF((I1="Exp Charge"),"INVOICE",IF((I1="TOTAL SALES"),"INVOICE", (IF((I1="Account payment"),"PAYMENT",IF((I1="Exp Check"),"PAYMENT","")))))) |
D1:D6 | D1 | =IF((I1="Exp Charge"),"Acounts Receivable",IF((I1="TOTAL SALES"),"SlBakery",IF((I1="Account Payment"),"Undeposited Funds",IF((I1="Exp Check"),"Accounts Receivable" )))) |
How I would like data to copied into sheet 2:
Book2.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | TRNS | 20656 | INVOICE | 01/02/2022 | Acounts Receivable | K.G Community Mart | 10.62 | 20656.00 | ||
2 | SPL | 20656 | INVOICE | 01/02/2022 | SlBakery | K.G Community Mart | 10.62 | 20656.00 | ||
3 | ENDTRNS | |||||||||
4 | TRNS | 20659 | CREDIT MEMO | 01/02/2022 | Acounts Receivable | K.G Community Mart | -41.22 | 20659 | ||
5 | SPL | 20659 | CREDIT MEMO | 01/02/2022 | SlBakery | K.G Community Mart | -41.22 | 20659.00 | ||
6 | ENDTRNS | |||||||||
7 | TRNS | 20660 | CREDIT MEMO | 01/02/2022 | Acounts Receivable | K.G Community Mart | -55.25 | 20660.00 | ||
8 | SPL | 20660 | CREDIT MEMO | 01/02/2022 | SlBakery | K.G Community Mart | -55.25 | 20660.00 | ||
Sheet2 |
How data gets copied into Sheet 2:
Book2.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | TRNS | 20656 | INVOICE | 01/02/2022 | Acounts Receivable | K.G Community Mart | 10.62 | 20656.00 | ||
2 | SPL | 20656 | INVOICE | 01/02/2022 | SlBakery | K.G Community Mart | 10.62 | 20656.00 | ||
3 | TRNS | 20659 | CREDIT MEMO | 01/02/2022 | Acounts Receivable | K.G Community Mart | -41.22 | 20659.00 | ||
4 | SPL | 20659 | CREDIT MEMO | 01/02/2022 | SlBakery | K.G Community Mart | -41.22 | 20659 | ||
5 | TRNS | 20660 | CREDIT MEMO | 01/02/2022 | Acounts Receivable | K.G Community Mart | -55.25 | 20660.00 | ||
6 | SPL | 20660 | CREDIT MEMO | 01/02/2022 | SlBakery | K.G Community Mart | -55.25 | 20660.00 | ||
Sheet2 |
My code:
VBA Code:
Sub transfering()
sheet1_last_row = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To sheet1_last_row
'Sheets("Sheet2").Cells(i, 1).Value = "TRNS"
d = i + 1
If Sheets("Sheet1").Cells(i, 1).Value = Sheets("Sheet1").Cells(d, 1).Value Then
Sheets("Sheet2").Cells(i, 1).Value = "TRNS"
Sheets("Sheet2").Cells(d, 1).Value = "SPL"
ElseIf Sheets("Sheet1").Cells(i, 1).Value < Sheets("Sheet1").Cells(d, 1).Value Then
Sheets("Sheet2").Cells(d, 1).Value = "ENDTRNS"
End If
Sheets("Sheet2").Cells(i, 2).Value = Sheets("Sheet1").Cells(i, 3).Value
Sheets("Sheet2").Cells(i, 3).Value = Sheets("Sheet1").Cells(i, 2).Value2
Sheets("Sheet1").Cells(i, 5).Copy
Sheets("Sheet2").Cells(i, 4).PasteSpecial (xlPasteValues)
Sheets("Sheet2").Cells(i, 5).Value = Sheets("Sheet1").Cells(i, 4).Value
Sheets("Sheet2").Cells(i, 6).Value = Sheets("Sheet1").Cells(i, 7).Value
''Sheets("Sheet2").Cells(i, 7).Value = Sheets("Sheet1").Cells(i, 10).Value
Sheets("Sheet1").Cells(i, 10).Copy
Sheets("Sheet2").Cells(i, 7).PasteSpecial (xlPasteValuesAndNumberFormats)
Sheets("Sheet2").Cells(i, 8).Value = Sheets("Sheet1").Cells(i, 3).Value
Next i
End Sub
Currently the ENDTRNS line gets overwritten by the next set of SPL and TRNS in the loop. Is it possible to get it to insert a new line with ENDTRNS then continue?