Help with clearing array

ToExcelOrNotToExcel

New Member
Joined
Jan 7, 2023
Messages
13
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone I was trying to solve a problem and someone created this code for me. I have a problem though. I want to separate a 1D array into a d array. My problem is that I want the 2d array to contain only the data of one will which after which I will perform some calculations based on the data in the array and then I would like it to be cleared and do the same thing again for the next line. I will post the data, the first solution and then the second one. Please feel free to answer to either of the two because they do the same thing. I also want to be able to call the array values outside of the with statement but it is giving me an out of range error, how do I solve this?

Betting forula 2022.xlsm
CE
3HM9;AM17;HM30;AM31;AM50;HM60;AM75;AM86;HM96;HM104;AM110;HM126
4AM31,10;AM50,31;HM60,10;AM75,31;AM86;HM96;HM104,87;AM110;HM126
5HA60,58;AA75;AA86;HA96;HA104,76;AA110
6HA9;AA17;HA30,86;AA31;AA50,87;HA60,80;AA75,59;AA86;HA96,18;HA104;AA110,81;HA126
7HA9,37;AA17;HA30,4;AA31,22;AA50,22;HA60,32;AA86,61;HA96,72;HA126
8HM9;AM17,17;HM30,86;AM31;AM50;HM60;AM75;AM86,83;HM104,3;AM110,80;HM126,79
9HD9;AD17,46;AD75,44;AD86;HD96;HD104;AD110;HD126
10HD9;AD17,40;HD30;AD31;AD50;HD80,80;AD75;AD86;HD96;HD104;AD110;HD126
11HD9;AD17;HD30,86;AD31;AD50;HD60;AD75;AD86;HD96;HD104;AD110;HD126
12HA9;AA17,60;HA30,71;AA31,68;AA50,68;HA60,67;AA75,70;HA96;HA104,87;AA110,52
13HM9,78;AM17,44;HM30;AM31;AM50;HM60;AM75,59;AM86,7;HM104,14;AM110,10;HM126,29
14AD17,44;HD30;AD31;AD50;HD60;AD75,46
15AD17,44;HD30;AD31;AD50;HD60;AD75,40;HD96;HD104;AD110,60
16AD75,50;AD86;AD110,30
17HD9;AD17;AD60,9;HD126
18HGK9;AGK17;HGK30;AGK31;AGK50;HGK60;AGK75;AGK86;HGK96;HGK104;AGK110;HGK126
19HA30,44;AA75,31;AA86,29
20HD30,4
21HM9,53;AM17,46;HM30,19;AM50,3;HM60,23;AM75,20;HM96;HM104;AM110,38;HM126,11
22AA17,30;HA30,46;AA31,80;AA50,59;HA104,3;AA110,9;HA126,61
23
24HM9,12;AM17,3;HM30,4
Football


Code:
Sub FillPlayerRating()
  Dim cell As Range
  Dim i As Long, n As Long
  Dim p As Variant, arr_2d As Variant
  
  With Range("CE3:CE24")
    n = Evaluate("=SUM(LEN(" & .Address & ")-LEN(SUBSTITUTE(" & .Address & ","";"",""""))+1)")
    ReDim arr_2d(1 To n, 1 To 2)
  
    For Each cell In .Cells
      For Each p In Split(cell, ";")
        i = i + 1
        arr_2d(i, 1) = Trim(Split(p, ",")(0))
        If InStr(1, p, ",") > 0 Then arr_2d(i, 2) = Trim(Split(p, ",")(1))
      Next
    Next
  End With
End Sub


The second solution

Code:
Sub test3()
  Dim c
  c = Split(Join(Application.Transpose(Range("CE3:CE24").Value), ";"), ";")
  With Range("CG3").Resize(UBound(c) + 1)
    .Value = Application.Transpose(c)
    .TextToColumns .Cells(1), xlDelimited, Comma:=True
  End With
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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