Impossible or Not

HappyChappy

Active Member
Joined
Jan 26, 2013
Messages
384
Office Version
  1. 2019
  2. 2010
  3. 2007
Platform
  1. Windows
Hi I have a problem which I don't think is possible in excel but thought I'd throw it out there as this site has some amazing members who have wowed me in the past.
I have two sheets one has data which i want pulled onto the 2nd sheet but in a very particular way. the cell has two numbers in it example 15 & 16 i need to pull the route number, Name and Registration onto sheet two but split the two routes.

Sheet 1 C1 =15 & 16 D1= Mr Smith F1= GH56TZH
C2= 17 D2 = Mr Jones F2 FD12YHJ

Sheet 2 C1= 15 D1= Mr Smith F1= GH56TZH
C2= 16 D2= Mr Smith F2= GH56TZH
C3= 17 C3= Mr Jones F3= FD12YHJ

Can a cell with two number be split in this way? Ps not all c1 cells have double numbers some are standard single ones

Regards
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
1. Is two the most numbers in a single cell?
2. If more are possible are they all separated by space then ampersand then space?
3. About how many rows are likely in the original data?
4. About how many rows are likely in the final result?
5. If it turns out a macro is the best way is that acceptable?
6. What version of Excel are you using?


Edit:
7. Are all the numbers 2 digits?
 
Last edited:
Upvote 0
Two numbers are the most entered separated by & maximum are 35 routes
Excel 2016 hope this helps
 
Upvote 0
So numbers 1 to 35 will be used but some in pairs ie: 4&5 as two routes for this vehicle on the day.
never thought it could be done was a shot in the dark. you say it needs to be in a macro to achieve the result.
will await the necessary code and thank you for the assistance.
 
Upvote 0
you say it needs to be in a macro to achieve the result.
I didn't say that before. I was trying to collect relevant information to decide. Now I am suggesting that is how I would do it. :)

Give this a try in a copy of your workbook after checking the sheet names for accuracy.

Rich (BB code):
Sub Get_Routes()
  Dim a As Variant, b As Variant, RouteNo As Variant
  Dim i As Long, lr As Long, k As Long
  
  With Sheets("Sheet 1")
    lr = .Range("C" & .Rows.Count).End(xlUp).Row
    a = Application.Index(.Cells, Evaluate("row(1:" & lr & ")"), Array(3, 4, 6))
  End With
  ReDim b(1 To 1000, 1 To 3)
  For i = 1 To UBound(a)
    For Each RouteNo In Split(Replace(a(i, 1), " ", ""), "&")
      k = k + 1
      b(k, 1) = RouteNo
      b(k, 2) = a(i, 2)
      b(k, 3) = a(i, 3)
    Next RouteNo
  Next i
  With Sheets("Sheet 2")
    .Range("C1:D1").Resize(k).Value = Application.Index(b, Evaluate("row(1:" & k & ")"), Array(1, 2))
    .Range("F1").Resize(k).Value = Application.Index(b, Evaluate("row(1:" & k & ")"), 3)
  End With
End Sub
 
Upvote 0
Hi Peter, just tried out the macro definitely on the right track, I needed to be a bit clearer on my needs
sheet 2 A4 is the start of data for my numbers c4 is for the name and j4 is for the Registration
Sheet1 c3:c44 is the number d3:d44 the name and m3:m44 is the Registration
it is amazing you are able to break it down never thought it was going to feezable
 
Upvote 0
See if this is better

Rich (BB code):
Sub Get_Routes_v2()
  Dim a As Variant, b As Variant, RouteNo As Variant
  Dim i As Long, lr As Long, k As Long
  
  With Sheets("Sheet 1")
    lr = .Range("C" & .Rows.Count).End(xlUp).Row
    a = Application.Index(.Cells, Evaluate("row(3:" & lr & ")"), Array(3, 4, 13))
  End With
  ReDim b(1 To 1000, 1 To 3)
  For i = 1 To UBound(a)
    For Each RouteNo In Split(Replace(a(i, 1), " ", ""), "&")
      k = k + 1
      b(k, 1) = RouteNo
      b(k, 2) = a(i, 2)
      b(k, 3) = a(i, 3)
    Next RouteNo
  Next i
  With Sheets("Sheet 2")
    .Range("A4").Resize(k).Value = Application.Index(b, Evaluate("row(1:" & k & ")"), 1)
    .Range("C4").Resize(k).Value = Application.Index(b, Evaluate("row(1:" & k & ")"), 2)
    .Range("J4").Resize(k).Value = Application.Index(b, Evaluate("row(1:" & k & ")"), 3)
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,749
Messages
6,180,725
Members
452,995
Latest member
isldboy

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