A simple macro for a simple Array...?

Dreamteam

New Member
Joined
Feb 22, 2018
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Hi all

Below is a list of data in col A of football results. The data pattern is consistent - Date of match; Home team; Score (home team first) and finally Away team. And then it moves onto the next result. I have been trying to simply move it over into a more readable format - starting with cell C2. I thought this would be easy but I am cannot seem to do this. I thought initially that I would put col A into an array and then move it to the table - but to no avail.

Any help would be much apprecitated.

Many thanks

Dt

Football - probabilities.xlsm
ABCDEFG
219.05. 16:00DateHome ClubHome GoalsAway GoalsAway Club
3Chelsea19.05. 16:00Chelsea21Everton
42 - 119.05. 16:00Liverpool10QPR
5Everton19.05. 16:00Manchester City23Norwich
619.05. 16:0019.05. 16:00Newcastle01Arsenal
7Liverpool19.05. 16:00Southampton11Stoke
81 - 0
9QPR
1019.05. 16:00
11Manchester City
122 - 3
13Norwich
1419.05. 16:00
15Newcastle
160 - 1
17Arsenal
1819.05. 16:00
19Southampton
201 - 1
21Stoke
Sheet5
 
I think this will do what you want. I notice that your example data started in A2 and the results started in C3
VBA Code:
Sub test()
    Dim arrInput As Variant
    Dim arrOutput As Variant
    Dim rngOutput As Range
    Dim i As Long, Pointer As Long
    Set rngOutput = Range("C3")
    
    With Range("A:A")
        With Range(.Cells(2, 1), .Cells(Rows.Count, 1).End(xlUp))
            ReDim arrOutput(1 To .Rows.Count / 4, 1 To 5)
            arrInput = .Value
        End With
    End With
    
    For i = 1 To UBound(arrInput, 1) Step 4
        Pointer = Pointer + 1
        arrOutput(Pointer, 1) = arrInput(i, 1)
        arrOutput(Pointer, 2) = arrInput(i + 1, 1)
        arrOutput(Pointer, 3) = Trim(Split(arrInput(i + 2, 1), "-")(0))
        arrOutput(Pointer, 4) = Trim(Split(arrInput(i + 2, 1) & "-", "-")(1))
        arrOutput(Pointer, 5) = arrInput(i + 3, 1)
    Next i
    
    rngOutput.Resize(Pointer, 5).Value = arrOutput
End Sub
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Footoo, Bo_Ry and now Mike - thankyou all!

All of the solutions that you have given all work!

Thank you all for your time (and patience!)

Dt
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,072
Latest member
DW Draft

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