Adjust Macros Formula Help

IdabaMalouki

New Member
Joined
Sep 10, 2024
Messages
15
Office Version
  1. 2021
Platform
  1. Windows
I have an irregular data set that looks like this:

Screenshot (36).png

VBA Code:
Sub organized_data_v1()
  Dim i As Long, k As Long
  
  Application.ScreenUpdating = False
  k = 2
  For i = 1 To Range("A" & Rows.Count).End(3).Row Step 20
    Range("C" & k).Value = Range("A" & i + 17)
    Range("D" & k).Resize(1, 6).Value = Application.Transpose(Range("A" & i + 3).Resize(6).Value)
    Range("D" & k + 1).Resize(1, 6).Value = Application.Transpose(Range("A" & i + 9).Resize(6).Value)
    k = k + 2
  Next
  Application.ScreenUpdating = True
End Sub

Can the above VBA code be tweaked to sort the above irregular dataset from colum A into columns C thru J as pictured above? Thanks in advance.
 
Something like this,
VBA Code:
Sub x()
    Dim w As Worksheet, i&, o&, r&, d
    Set w = ActiveSheet
    r = w.Cells(w.Rows.Count, 1).End(3).Row: o = 2

    For i = 1 To r
        If InStr(1, LCase(w.Cells(i, 1)), "spread") > 0 Then
            On Error Resume Next
            d = Array( _
                w.Cells(i + 23, 1).Value, w.Cells(i + 3, 1).Value, w.Cells(i + 5, 1).Value, _
                w.Cells(i + 7, 1).Value, w.Cells(i + 8, 1).Value, w.Cells(i + 9, 1).Value, _
                w.Cells(i + 10, 1).Value, w.Cells(i + 11, 1).Value, w.Cells(i + 12, 1).Value, _
                w.Cells(i + 14, 1).Value, w.Cells(i + 16, 1).Value, w.Cells(i + 17, 1).Value, _
                w.Cells(i + 18, 1).Value, w.Cells(i + 19, 1).Value, w.Cells(i + 20, 1).Value)

            w.Range(w.Cells(o, 3), w.Cells(o, 10)).Value = _
                Application.Transpose(Application.Index(d, Evaluate("ROW(1:8)")))

            w.Range(w.Cells(o + 1, 4), w.Cells(o + 1, 10)).Value = _
                Application.Transpose(Application.Index(d, Evaluate("ROW(9:15)")))

            w.Cells(o, 3).NumberFormat = "h:mm AM/PM"
            o = o + 2: On Error GoTo 0
        End If
    Next
End Sub
 
Upvote 0
Solution
Something like this,
VBA Code:
Sub x()
    Dim w As Worksheet, i&, o&, r&, d
    Set w = ActiveSheet
    r = w.Cells(w.Rows.Count, 1).End(3).Row: o = 2

    For i = 1 To r
        If InStr(1, LCase(w.Cells(i, 1)), "spread") > 0 Then
            On Error Resume Next
            d = Array( _
                w.Cells(i + 23, 1).Value, w.Cells(i + 3, 1).Value, w.Cells(i + 5, 1).Value, _
                w.Cells(i + 7, 1).Value, w.Cells(i + 8, 1).Value, w.Cells(i + 9, 1).Value, _
                w.Cells(i + 10, 1).Value, w.Cells(i + 11, 1).Value, w.Cells(i + 12, 1).Value, _
                w.Cells(i + 14, 1).Value, w.Cells(i + 16, 1).Value, w.Cells(i + 17, 1).Value, _
                w.Cells(i + 18, 1).Value, w.Cells(i + 19, 1).Value, w.Cells(i + 20, 1).Value)

            w.Range(w.Cells(o, 3), w.Cells(o, 10)).Value = _
                Application.Transpose(Application.Index(d, Evaluate("ROW(1:8)")))

            w.Range(w.Cells(o + 1, 4), w.Cells(o + 1, 10)).Value = _
                Application.Transpose(Application.Index(d, Evaluate("ROW(9:15)")))

            w.Cells(o, 3).NumberFormat = "h:mm AM/PM"
            o = o + 2: On Error GoTo 0
        End If
    Next
End Sub
Thank you, Maestro!!!
 
Upvote 0

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