Attached is you mock workbook updated to include the macro TransferToSheet3 which I believe accomplishes what you are trying to achieve. Below is the code.
Dim i As Long, x As Long, Sht3 As Worksheet, u As Long, LR As String 'declare variables
Set Sht3 = Sheets("Sheet3") 'set the variable Sht3 equal to the worksheet named Sheet3
With Sheets("DaY") 'with the worksheet DaY
For x = 3 To 6 'start x at three and loop through until 6
'x will be used to reference the columns C, D and E in the worksheet DaY
For i = 60 To 82 Step 2 'loop through the variable i starting at 60 and going to 82
'looping through only the even numbers
'i will be used to reference the IOI/ALLO's cells and whether they contain a value
'so you can determine whether to transfer information or not
If .Cells(i, x) > 0 Then 'if the value in the cell in row i(the current number in the i loop)
'column x (the current x in the x loop) is greater than 0 then...
LR = Sht3.Range("A6555").End(xlUp).Row + 1 'set LR equal to the first empty row in the worksheet Sheet3
For u = 1 To 37 'loop through the variable u from 1 to 37
Select Case u 'if the current u in the loop is...
Case 3 'the number 3 (column C (BROKER)) then..
Sht3.Cells(LR, u) = .Cells(i - 1, 1) 'set the cell (worksheet sheet3) in row LR(defined above), column u (the current u in the u loop)
'equal to the cell (worksheet DaY) in row i-1 (current i in the loop minus 1), column A
Case 12, 13 'the number is 12 or 13 (column L or M (ALLO,IOI)) then...
Sht3.Cells(LR, u) = .Cells(i, x) 'set the cell (worksheet sheet3) in row LR(defined above), column u (the current u in the u loop)
'equal to the cell (worksheet DaY) in row i (current i in the loop ), column x (current x in the loop)
Case Else
Sht3.Cells(LR, u) = .Cells(u, x) 'set the cell (worksheet sheet3) in row LR(defined above), column u (the current u in the u loop)
'equal to the cell (worksheet DaY) in row u (current u in the loop ), column x (current x in the loop)
End Select
Next u 'move to next u in the u loop
End If
Next i 'move to next i in the i loop
Next x 'move to next x in the x loop
End With
Open the workbook and press Alt+F8 to bring up the macro window. Then select the TransferToSheet3 macro and select Run. Go to the worksheet Sheet3 and the information should appear in row 21 under the Testing Below header.
To insert this code into your workbook
1. Press Alt+F8
2. Clear the macro name field and then type TransferToSheet3
3. Select the create option
4. Copy and paste the above code in between the Sub TransferToSheet3() and End Sub
5. Take a moment to read through the code, I have left comments that will appear in green that will let you know what each line of the code is doing.
6. Close out of Visual Basic
Let me know if this works for you!
Thanks!
Bookmarks