How to number sequential items and put number all numbers into a cell with a delimeter

theloveofwisdom

New Member
Joined
Nov 20, 2015
Messages
10
Please help me write a vba that can create the data in the second column. Any help will be appreciated. There will be a large amount of tickets, and each individual may purchase as many tickets as they like... probably no more than a few hounded.

# of ticketsticket #
41,2;3;4
35;6;7
28;9
610;11;12;13;14;15
116
317;18;19

<tbody>
</tbody>
 
Thank you all. I have a followup request.

What if I want to distinguish between two types of ticket orders. This would seem to need two different counters dependent on the column for # of tickets and the column for Order type. Could the any of the above functions code be modified to have two counters so as to generate the output below in the Ticket #s column? A modified version of any of the previous code samples (which all work for the initial request) will do, or a completely new one also.


The only other option I have, which I will probably resort to, is to have two different sheet- one for Mail orders, and one for Online orders. If anyone can chime in with another piece of code, that would be great, but you all have helpful beyond words already.




First NameLast NameOrder Type# of TicketsTicket #s
JoeSmithOnline7i1;i2;i3;i4;i5;i6;i7
SteveJonesMail5m1;m2;m3;m4;m5
NickSmithOnline5i8;i9;i10;i11;i12
NickJonesOnline9i13;i14;i15;i16;i17;i18;i19;i20;i21
NickStevensMail6m6;m7;m8;m9;m10;m11

<tbody>
</tbody>
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I need to go offline right now, but will look at this later if someone else hasn't provided a solution for you.
 
Upvote 0
Thank you all. I have a followup request.

What if I want to distinguish between two types of ticket orders. This would seem to need two different counters dependent on the column for # of tickets and the column for Order type. Could the any of the above functions code be modified to have two counters so as to generate the output below in the Ticket #s column? A modified version of any of the previous code samples (which all work for the initial request) will do, or a completely new one also.


The only other option I have, which I will probably resort to, is to have two different sheet- one for Mail orders, and one for Online orders. If anyone can chime in with another piece of code, that would be great, but you all have helpful beyond words already.




First NameLast NameOrder Type# of TicketsTicket #s
JoeSmithOnline7i1;i2;i3;i4;i5;i6;i7
SteveJonesMail5m1;m2;m3;m4;m5
NickSmithOnline5i8;i9;i10;i11;i12
NickJonesOnline9i13;i14;i15;i16;i17;i18;i19;i20;i21
NickStevensMail6m6;m7;m8;m9;m10;m11

<tbody>
</tbody>
This modification should do it.
Code:
Sub TicketNums()
Const O As String = "Online"
Const M As String = "Mail"
Dim R As Range, Vin As Variant, Vout As Variant, Cum As Long, First  As Long, j As Long, k As Long, S As String
Set R = Range("A2:D" & Cells(Rows.Count, "A").End(xlUp).Row)
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
First = 1
For j = LBound(Vin, 1) To UBound(Vin, 1)
       Cum = Cum + Val(Vin(j, 4))
       For k = First To Cum
        Select Case Vin(j, 3)
            Case O: S = S & ";" & "i" & k
            Case M: S = S & ";" & "m" & k
        End Select
       Next k
       Vout(j, 1) = Right(S, Len(S) - 1)
       First = Cum + 1
       S = ""
Next j
Application.ScreenUpdating = False
R.Columns(4).Offset(0, 1).Value = Vout
R.Columns(4).Offset(0, 1).EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you very much for your time and input. However, I think there is a slight mistake in the code below. If you look closely, the ticket counter for Case M should be independant of the that for Case O- such that the first Mail ticket should be numbered "m1;" while the code below generates a "m8;". If you have time, It would be great to get this running.



First NameLast NameOrder Type# of TicketsTicket #s
JoeSmithOnline7i1;i2;i3;i4;i5;i6;i7
SteveJonesMail5m1;m2;m3;m4;m5
NickSmithOnline5i8;i9;i10;i11;i12
NickJonesOnline9i13;i14;i15;i16;i17;i18;i19;i20;i21
NickStevensMail6m6;m7;m8;m9;m10;m11

<tbody>
</tbody>



This modification should do it.
Code:
Sub TicketNums()
Const O As String = "Online"
Const M As String = "Mail"
Dim R As Range, Vin As Variant, Vout As Variant, Cum As Long, First  As Long, j As Long, k As Long, S As String
Set R = Range("A2:D" & Cells(Rows.Count, "A").End(xlUp).Row)
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
First = 1
For j = LBound(Vin, 1) To UBound(Vin, 1)
       Cum = Cum + Val(Vin(j, 4))
       For k = First To Cum
        Select Case Vin(j, 3)
            Case O: S = S & ";" & "i" & k
            Case M: S = S & ";" & "m" & k
        End Select
       Next k
       Vout(j, 1) = Right(S, Len(S) - 1)
       First = Cum + 1
       S = ""
Next j
Application.ScreenUpdating = False
R.Columns(4).Offset(0, 1).Value = Vout
R.Columns(4).Offset(0, 1).EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Guess I didn't look closely. :p Try this:
Code:
Sub TicketNums()
Const O As String = "Online"
Const M As String = "Mail"
Dim R As Range, Vin As Variant, Vout As Variant, CumM As Long, CumO As Long, _
    FirstM As Long, FirstO As Long, j As Long, k As Long, SM As String, SO As String
Set R = Range("A2:D" & Cells(Rows.Count, "A").End(xlUp).Row)
Vin = R.Value
ReDim Vout(1 To UBound(Vin, 1), 1 To 1)
FirstO = 1
FirstM = 1
For j = LBound(Vin, 1) To UBound(Vin, 1)
    Select Case Vin(j, 3)
        Case O
            CumO = CumO + Val(Vin(j, 4))
            For k = FirstO To CumO
                SO = SO & ";" & "i" & k
            Next k
            Vout(j, 1) = Right(SO, Len(SO) - 1)
            SO = ""
            FirstO = CumO + 1
        Case M
            CumM = CumM + Val(Vin(j, 4))
            For k = FirstM To CumM
                SM = SM & ";" & "m" & k
            Next k
            Vout(j, 1) = Right(SM, Len(SM) - 1)
            SM = ""
            FirstM = CumM + 1
    End Select
Next j
Application.ScreenUpdating = False
R.Columns(4).Offset(0, 1).Value = Vout
R.Columns(4).Offset(0, 1).EntireColumn.AutoFit
Application.ScreenUpdating = True
End Sub
 
Upvote 0
To slightly beat a dead horse, try this in E2

=IF(D2="Online", "l", "m")&NumeralSequence(SUM(D$1:D1)+1,SUM(D$1:D2), ";"&IF(C1="Online", "l", "m"))
 
Upvote 0
Please help me write a vba that can create the data in the second column. Any help will be appreciated. There will be a large amount of tickets, and each individual may purchase as many tickets as they like... probably no more than a few hunded.

First NameLast NameOrder Type# of TicketsTicket #s
JoeSmithOnline7i1;i2;i3;i4;i5;i6;i7
SteveJonesMail5m1;m2;m3;m4;m5
NickSmithOnline5i8;i9;i10;i11;i12
NickJonesOnline9i13;i14;i15;i16;i17;i18;i19;i20;i21
NickStevensMail6m6;m7;m8;m9;m10;m11

<tbody>
</tbody>
I think this macro will also do what you want...
Code:
[table="width: 500"]
[tr]
	[td]Sub TicketNumbers()
  Dim R As Long, LastI As Long, LastM As Long, TempLast As Long, Temp As String, Online As Boolean
  Application.ScreenUpdating = False
  For R = 2 To Cells(Rows.Count, "C").End(xlUp).Row
    Online = LCase(Cells(R, "C").Value) = "online"
    TempLast = IIf(Online, LastI, LastM) + Cells(R, "D").Value
    Temp = IIf(Online, "i", "m") & Join(Evaluate("TRANSPOSE(ROW(" & IIf(Online, LastI, LastM) + 1 & ":" & TempLast & "))"), IIf(Online, ";i", ";m"))
    If Online Then LastI = TempLast Else LastM = TempLast
    Cells(R, "E").Value = Temp
  Next
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Excellent!! This worked for me. This community is awesome. Thank you very much!
It is not clear whose code worked for you nor who it is that you are thanking, but I am sure the several participants in this thread will join me in saying a collective, "You are quite welcome".
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,331
Latest member
smckenzie2016

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