Need program to move to insert row

Blassevba

New Member
Joined
Apr 4, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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
Book2.xlsm
ABCDEFGHIJ
13564INVOICE20656Acounts Receivable01/02/202298K.G Community MartExp Charge10.62
23564INVOICE20656SlBakery01/02/202298K.G Community MartTOTAL SALES10.62
33566CREDIT MEMO20659Acounts Receivable01/02/202298K.G Community MartExp Charge-41.22
43566CREDIT MEMO20659SlBakery01/02/202298K.G Community MartTOTAL SALES-41.22
53567CREDIT MEMO20660Acounts Receivable01/02/202298K.G Community MartExp Charge-55.25
63567CREDIT MEMO20660SlBakery01/02/202298K.G Community MartTOTAL SALES-55.25
Sheet1
Cell Formulas
RangeFormula
B1:B6B1=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:D6D1=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
ABCDEFGH
1TRNS20656INVOICE01/02/2022Acounts ReceivableK.G Community Mart10.6220656.00
2SPL20656INVOICE01/02/2022SlBakeryK.G Community Mart10.6220656.00
3ENDTRNS
4TRNS20659CREDIT MEMO01/02/2022Acounts ReceivableK.G Community Mart-41.2220659
5SPL20659CREDIT MEMO01/02/2022SlBakeryK.G Community Mart-41.2220659.00
6ENDTRNS
7TRNS20660CREDIT MEMO01/02/2022Acounts ReceivableK.G Community Mart-55.2520660.00
8SPL20660CREDIT MEMO01/02/2022SlBakeryK.G Community Mart-55.2520660.00
Sheet2


How data gets copied into Sheet 2:
Book2.xlsm
ABCDEFGH
1TRNS20656INVOICE01/02/2022Acounts ReceivableK.G Community Mart10.6220656.00
2SPL20656INVOICE01/02/2022SlBakeryK.G Community Mart10.6220656.00
3TRNS20659CREDIT MEMO01/02/2022Acounts ReceivableK.G Community Mart-41.2220659.00
4SPL20659CREDIT MEMO01/02/2022SlBakeryK.G Community Mart-41.2220659
5TRNS20660CREDIT MEMO01/02/2022Acounts ReceivableK.G Community Mart-55.2520660.00
6SPL20660CREDIT MEMO01/02/2022SlBakeryK.G Community Mart-55.2520660.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?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top