Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 1 normal form


Hi, I hv an excel file which contain 2 colums, the first column is
STATE and 2nd column is zipcode. The 2nd column contain a list of
zipecodes seperated by ",".
My question : how do I separet each of the zipcode and copy it along
with column 1 to another worksheet in the same w/book?

Eg : the source file =

state1 | 5500, 5511, 5522
state2 | 6300, 6800
state3 | 45000
state4 |
state5 | 4100, 4200

the expected file =

state1 | 5500
state1 | 5511
state1 | 5522
state2 | 6300
state2 | 6800
state3 | 45000
state4 |
state5 | 4100
state5 | 4200

Thanks in advance.


--
swchee
------------------------------------------------------------------------
swchee's Profile: http://www.excelforum.com/member.php...o&userid=24279
View this thread: http://www.excelforum.com/showthread...hreadid=378942

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 1 normal form

This worked for me--but it destroys the original worksheet. Save before you run
it and close without saving if it doesn't work:

Option Explicit
Sub testme01()

Dim wks As Worksheet
Dim newWks As Worksheet
Dim ValuesToCopy As Long
Dim iRow As Long
Dim oRow As Long
Dim FirstRow As Long
Dim LastRow As Long

Set wks = Worksheets("sheet1")
Set newWks = Worksheets.Add

With wks.Range("b:b")
.Cells.TextToColumns Destination:=.Columns(1), _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False
End With

With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

oRow = 1
For iRow = FirstRow To LastRow
'
' newWks.Cells(oRow, "A").Value = .Cells(iRow, "A").Value
' newWks.Cells(oRow, "B").Value = .Cells(oRow, "B").Value

ValuesToCopy = Application.CountA(.Range(.Cells(iRow, "B"), _
.Cells(iRow, .Columns.Count)))

If ValuesToCopy = 0 Then
ValuesToCopy = 1
End If

newWks.Cells(oRow, "A").Resize(ValuesToCopy, 1).Value _
= .Cells(iRow, "A").Value

.Cells(iRow, "B").Resize(1, ValuesToCopy).Copy
newWks.Cells(oRow, "B").PasteSpecial Transpose:=True

oRow = oRow + ValuesToCopy
Next iRow
End With
End Sub

swchee wrote:

Hi, I hv an excel file which contain 2 colums, the first column is
STATE and 2nd column is zipcode. The 2nd column contain a list of
zipecodes seperated by ",".
My question : how do I separet each of the zipcode and copy it along
with column 1 to another worksheet in the same w/book?

Eg : the source file =

state1 | 5500, 5511, 5522
state2 | 6300, 6800
state3 | 45000
state4 |
state5 | 4100, 4200

the expected file =

state1 | 5500
state1 | 5511
state1 | 5522
state2 | 6300
state2 | 6800
state3 | 45000
state4 |
state5 | 4100
state5 | 4200

Thanks in advance.

--
swchee
------------------------------------------------------------------------
swchee's Profile: http://www.excelforum.com/member.php...o&userid=24279
View this thread: http://www.excelforum.com/showthread...hreadid=378942


--

Dave Peterson
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
Normal distribution Alexandra Lopes Excel Worksheet Functions 2 December 4th 08 02:36 PM
normal.dot Ron New Users to Excel 4 July 13th 06 06:48 PM
currency different from normal Onrey Excel Discussion (Misc queries) 3 March 14th 05 08:17 PM
Normal Distribution? Anthony Slater Excel Discussion (Misc queries) 2 March 8th 05 07:21 PM
Normal Distribution littlecharva Excel Programming 3 April 2nd 04 04:39 AM


All times are GMT +1. The time now is 07:09 AM.

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

About Us

"It's about Microsoft Excel"