I'm in need of some assistance to condense my code. I've created quite a large spreadsheet for orders and invoices for my company. With its size and the amount of code, it's pretty slow in execution.
The coding I would like some help with should first of all copy cells in column A & B of the current active row then look through a row, through use of the row with column "A" being the current active cell. It needs to find a product which references to the products stock page, the cell will start at an offset of 13, it will activate the page of the product, and paste the copied cells to a table staring at range "F4", but it then needs to look though to see if there's another product on the orders page which will then be an offset of 2 each time. Below is my current code, any insight would be extremely helpful
If Not neworder.cbotype.Value = "L-Wholesale-Abbas" Then
If Not neworder.cbotype.Value = "V-Wholesale-Abbas" Then
'(1)
Sheets("Orders").Select
ActiveCell.Select
ActiveCell.Resize(1, 2).Select
Selection.Copy
ActiveCell.Offset(0, 13).Select
Worksheets(ActiveCell.Value).Activate
lRow = ActiveSheet.Range("f4").CurrentRegion.Rows.Count
With ActiveSheet.Range("f4")
Range("f4").Select
Selection.End(xlDown).Select
.Offset(lRow, 0).Select
Selection.PasteSpecial
Range("h2:i2").Copy
.Offset(lRow, 2).PasteSpecial
End With
'(2)
On Error Resume Next
Sheets("Orders").Select
ActiveCell.Select
If Not IsEmpty(ActiveCell.Offset(0, 2)) Then
ActiveCell.Offset(0, -13).Select
ActiveCell.Resize(1, 2).Select
Selection.Copy
ActiveCell.Offset(0, 15).Select
Worksheets(ActiveCell.Value).Activate
lRow2 = ActiveSheet.Range("f4").CurrentRegion.Rows.Count
With ActiveSheet.Range("f4")
Range("f4").Select
Selection.End(xlDown).Select
.Offset(lRow2, 0).Select
Selection.PasteSpecial
Range("h2:i2").Copy
.Offset(lRow2, 2).PasteSpecial
End With
Else
End If
It then continues with (2) repeating up to (50)
Below is a row from the orders page where this code works, i've put an "x" in two empty columns, the cells my code is looking for are the ones at the end, there is item quantity then item reference repeated 50 times
1-Jun VK-LG-3224_1 Dropship Bellezza scarf rahima begum Seller £7.00 PayPal £6.56 x x 1 VIVK-N-NP-203 1 VIVK-N-NP-197
Step by Step: 1) copy cells A & B in last row 2) open sheet name in column N 3) paste in last row from table starting F4 4) go back to orders sheet 5) copy cells A & B from same row as earlier 6) open sheet name in column P 7) paste in last row from table starting F4
This continues along the same row, moving along two columns at a time until the last column which is DH