Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default IF/THEN/ELSE for sequential numbers

I have a series of sequential numbers that I want to output as two
parts of a whole component.

Example: 1, 2, 3, 4, 5, 6, etc would become 1A, 1B, 2A, 2B, 3A, 3B,
etc.

I was thinking of assigning odd/even for A/B, but then I come out with
1A, 2B, 3A, 4B, etc. With 20 or more numbers it becomes even more
unwieldy.

Suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default IF/THEN/ELSE for sequential numbers

Juggler,

I'm not sure what you mean by output but the code below takes a range of
numbers and appends an A and a B to each in the 2 columns to the right.

Sub addanAorB()
Dim myRange As Range
Set myRange = Range("A1:A10")
For Each c In myRange
c.Select
ActiveCell.Offset(0, 1).Value = c.Value & "A"
ActiveCell.Offset(0, 2).Value = c.Value & "B"
Next
End Sub

Mike

"juggler" wrote:

I have a series of sequential numbers that I want to output as two
parts of a whole component.

Example: 1, 2, 3, 4, 5, 6, etc would become 1A, 1B, 2A, 2B, 3A, 3B,
etc.

I was thinking of assigning odd/even for A/B, but then I come out with
1A, 2B, 3A, 4B, etc. With 20 or more numbers it becomes even more
unwieldy.

Suggestions?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default IF/THEN/ELSE for sequential numbers

On Jun 12, 7:19 am, Mike H wrote:
Juggler,

I'm not sure what you mean by output but the code below takes a range of
numbers and appends an A and a B to each in the 2 columns to the right.

Sub addanAorB()
Dim myRange As Range
Set myRange = Range("A1:A10")
For Each c In myRange
c.Select
ActiveCell.Offset(0, 1).Value = c.Value & "A"
ActiveCell.Offset(0, 2).Value = c.Value & "B"
Next
End Sub

Mike



"juggler" wrote:
I have a series of sequential numbers that I want to output as two
parts of a whole component.


Example: 1, 2, 3, 4, 5, 6, etc would become 1A, 1B, 2A, 2B, 3A, 3B,
etc.


I was thinking of assigning odd/even for A/B, but then I come out with
1A, 2B, 3A, 4B, etc. With 20 or more numbers it becomes even more
unwieldy.


Suggestions?- Hide quoted text -


- Show quoted text -


I am trying to alter the numbering sequence, not just add an 'A' or
'B'. In a string of numbers such as 1,2,3,4,5,6,7,8,9,10 I want to end
up with 1A, 1B, 2A, 2B, 3A, 3B, 4A, 4B, 5A, 5B.

For example, the problem in writing the code is how I identify that I
want the numeral 9 to change to 5A?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default IF/THEN/ELSE for sequential numbers

Try this function. You should add error/array checking.

Private Function ReSequence(SequenceCount As Long, CharList As Variant) As
String()
Dim j As Long
Dim Counter As Long
Dim Index As Long
Dim OutPut() As String

ReDim OutPut(1 To SequenceCount)

Do
Counter = Counter + 1
For j = LBound(CharList) To UBound(CharList)
Index = Index + 1
If Index SequenceCount Then GoTo Finish
OutPut(Index) = Counter & CharList(j)
Next
Loop

Finish:
ReSequence = OutPut()

End Function

And call it with something like:

Private Sub CommandButton1_Click()

Const Chars As String = "A,B"
'Const Chars As String = "i,ii,iii"
Selection.Value = Application.Transpose(ReSequence(Selection.Cells.C ount,
Split(Chars, ",")))

End Sub

NickHK

"juggler" wrote in message
oups.com...
On Jun 12, 7:19 am, Mike H wrote:
Juggler,

I'm not sure what you mean by output but the code below takes a range of
numbers and appends an A and a B to each in the 2 columns to the right.

Sub addanAorB()
Dim myRange As Range
Set myRange = Range("A1:A10")
For Each c In myRange
c.Select
ActiveCell.Offset(0, 1).Value = c.Value & "A"
ActiveCell.Offset(0, 2).Value = c.Value & "B"
Next
End Sub

Mike



"juggler" wrote:
I have a series of sequential numbers that I want to output as two
parts of a whole component.


Example: 1, 2, 3, 4, 5, 6, etc would become 1A, 1B, 2A, 2B, 3A, 3B,
etc.


I was thinking of assigning odd/even for A/B, but then I come out with
1A, 2B, 3A, 4B, etc. With 20 or more numbers it becomes even more
unwieldy.


Suggestions?- Hide quoted text -


- Show quoted text -


I am trying to alter the numbering sequence, not just add an 'A' or
'B'. In a string of numbers such as 1,2,3,4,5,6,7,8,9,10 I want to end
up with 1A, 1B, 2A, 2B, 3A, 3B, 4A, 4B, 5A, 5B.

For example, the problem in writing the code is how I identify that I
want the numeral 9 to change to 5A?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default IF/THEN/ELSE for sequential numbers

Just an additional approach.

Sub AA()
Dim i As Long, j As Long
Dim s As String
For i = 1 To 6
For j = 65 To 66
s = s & i & Chr(j) & ","
Next j
Next i
MsgBox Left(s, Len(s) - 1)
End Sub



--
Regards,
Tom Ogilvy


"juggler" wrote:

I have a series of sequential numbers that I want to output as two
parts of a whole component.

Example: 1, 2, 3, 4, 5, 6, etc would become 1A, 1B, 2A, 2B, 3A, 3B,
etc.

I was thinking of assigning odd/even for A/B, but then I come out with
1A, 2B, 3A, 4B, etc. With 20 or more numbers it becomes even more
unwieldy.

Suggestions?




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sequential Numbers LiAD Excel Discussion (Misc queries) 5 January 8th 09 03:39 PM
Sequential Numbers Scott Hemphill Excel Worksheet Functions 8 August 6th 07 03:38 PM
Sequential Numbers abcdexcel Excel Discussion (Misc queries) 3 January 18th 06 11:06 AM
sequential numbers Harley Excel Worksheet Functions 1 January 12th 06 09:57 PM
sequential numbers AndrewRichardWood Excel Discussion (Misc queries) 2 July 20th 05 05:00 PM


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"