Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default how can I put a number from a sequence in every row in excel?

A B

Angola-Unitel Mobile 244-92
Anguilla-Digicel Mobile 1264-581, 1264-582, 1264-583, 1264-584
Anguilla-Mobile 1264-235, 1264-469, 1264-476, 1264-536
Anguilla-Other 1264
Antigua & Barbuda-Mobile 1268-464, 1268-72, 1268-764, 1268-770
Antigua & Barbuda-Other 1268
Argentina-Buenos Aires 54-11
Argentina-Central 54-230, 54-232, 54-291, 54-299, 54-342,
54-348

I have those sequences of numbers, first of all I want to take off the "-"
from those numbers it'll be looks like that: "1264581" not "1264-581", and
the big step, I want to put every number from a sequence (for exemple from
B2) bottom, it should be like this:

A B
Angola-Unitel Mobile 24492
Anguilla-Digicel Mobile 1264581
Anguilla-Digicel Mobile 1264582
Anguilla-Digicel Mobile 1264583
Anguilla-Digicel Mobile 1264584
Anguilla-Mobile 1264235
Anguilla-Mobile 1264469
Anguilla-Mobile 1264476
Anguilla-Mobile 1264536
Anguilla-Other 1264
Antigua & Barbuda-Mobile 1268464
Antigua & Barbuda-Mobile 126872
Antigua & Barbuda-Mobile 1268764
Antigua & Barbuda-Mobile 1268770
Antigua & Barbuda-Other 1268
Argentina-Buenos Aires 5411
Argentina-Central 54230
Argentina-Central 54232
Argentina-Central 54291
Argentina-Central 54299
Argentina-Central 54342
Argentina-Central 54348

thank you.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default how can I put a number from a sequence in every row in excel?

How about:

Option Explicit
Sub testme()
Dim CurWks As Worksheet
Dim NewWks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim oRow As Long
Dim HowMany As Long
Dim mySplit As Variant
Dim myStr As String

Set CurWks = Worksheets("Sheet1")
Set NewWks = Worksheets.Add

With CurWks
FirstRow = 1 'no headers!
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

oRow = 1
For iRow = FirstRow To LastRow
myStr = .Cells(iRow, "B").Value
'replace the spaces and hyphens
myStr = Replace(myStr, " ", "")
myStr = Replace(myStr, "-", "")

'split the values based on the comma
mySplit = Split(myStr, ",")

'how many new rows do we need?
HowMany = UBound(mySplit) - LBound(mySplit) + 1

'assign the values to column A
NewWks.Cells(oRow, "A").Resize(HowMany, 1).Value _
= .Cells(iRow, "A").Value

'put those split values into column B
NewWks.Cells(oRow, "B").Resize(HowMany, 1).Value _
= Application.Transpose(mySplit)

'get ready for next record
oRow = oRow + HowMany

Next iRow
End With

'sort the new sheet by column A, then B
With NewWks.UsedRange
.Sort key1:=.Columns(1), order1:=xlAscending, _
key2:=.Columns(2), order2:=xlAscending, _
header:=xlNo
.Columns.AutoFit
End With

End Sub


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

diaExcel wrote:

A B

Angola-Unitel Mobile 244-92
Anguilla-Digicel Mobile 1264-581, 1264-582, 1264-583, 1264-584
Anguilla-Mobile 1264-235, 1264-469, 1264-476, 1264-536
Anguilla-Other 1264
Antigua & Barbuda-Mobile 1268-464, 1268-72, 1268-764, 1268-770
Antigua & Barbuda-Other 1268
Argentina-Buenos Aires 54-11
Argentina-Central 54-230, 54-232, 54-291, 54-299, 54-342,
54-348

I have those sequences of numbers, first of all I want to take off the "-"
from those numbers it'll be looks like that: "1264581" not "1264-581", and
the big step, I want to put every number from a sequence (for exemple from
B2) bottom, it should be like this:

A B
Angola-Unitel Mobile 24492
Anguilla-Digicel Mobile 1264581
Anguilla-Digicel Mobile 1264582
Anguilla-Digicel Mobile 1264583
Anguilla-Digicel Mobile 1264584
Anguilla-Mobile 1264235
Anguilla-Mobile 1264469
Anguilla-Mobile 1264476
Anguilla-Mobile 1264536
Anguilla-Other 1264
Antigua & Barbuda-Mobile 1268464
Antigua & Barbuda-Mobile 126872
Antigua & Barbuda-Mobile 1268764
Antigua & Barbuda-Mobile 1268770
Antigua & Barbuda-Other 1268
Argentina-Buenos Aires 5411
Argentina-Central 54230
Argentina-Central 54232
Argentina-Central 54291
Argentina-Central 54299
Argentina-Central 54342
Argentina-Central 54348

thank you.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default how can I put a number from a sequence in every row in excel?


thank you so much, why I'm not thinking about it?, anyway thanks a lot
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,180
Default how can I put a number from a sequence in every row in excel?

Once you got your data arranged with Text to Columns
and Find/Replace, you can do "the big step" with
John Walkenbach's reverse pivot table at:
http://tinyurl.com/2xykg6
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
Show Next Number in sequence Steven Brookes Excel Worksheet Functions 1 December 1st 06 05:39 AM
How can I match a random number with closest number from sequence? Matt Excel Worksheet Functions 4 August 3rd 06 01:22 AM
Display zero at the begnning of a number sequence in Excel Janelle Lister Excel Discussion (Misc queries) 2 July 27th 06 03:54 PM
Number sequence Brento Excel Discussion (Misc queries) 3 July 15th 06 11:41 PM
number sequence gap Judi Mason Excel Worksheet Functions 1 January 16th 06 07:08 PM


All times are GMT +1. The time now is 07:08 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"