moving and filtering data

SpringP

New Member
Joined
Sep 19, 2003
Messages
4
i have a series of rows in a column that has customers (200+ cust)info in it.

Company Name
Street Address, City, State, Zipcode
Phone Number

i need it to be

|Company Name | Street address | City | State | ZipCode | Phone Number |

| = column

thank you for any advice or help
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I do it as a 2-step process... copying the yellow highlighted area and pasting into the pink highlighted area...
Book1
ABCDEF
1ABCCompayABCCompay123MainSt,Austin,Texas,78704512-555-1212
2123MainSt,Austin,Texas,78704
3512-555-1212
4XYZInc.XYZInc.456MainSt,Austin,Texas,78704512-555-1213
5456MainSt,Austin,Texas,78704
6512-555-1213
7Acme,Inc.Acme,Inc.888Blueberry,Austin,Texas,78704512-555-1214
8888Blueberry,Austin,Texas,78704
9512-555-1214
10
11
Sheet2


Then after inserting 3 additional columns to the right of column C:C I'd use the Data | Text to Columns... menu command to parse the comma delimited address info.
 
Upvote 0
Try this:

Code:
Sub Test()
    Dim Sh As Worksheet
    Dim Rng As Range
    Dim ShNew As Worksheet
    Dim x As Long
    Dim r As Long
    Set Sh = Worksheets("Sheet1")
    Set Rng = Sh.Range("A1:A" & Sh.Range("A65536").End(xlUp).Row)
    Rng.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1))
    Set ShNew = Worksheets.Add
    r = 1
    For x = 1 To Rng.Rows.Count Step 3
        ShNew.Cells(r, 1) = Rng.Cells(x, 1)
        ShNew.Cells(r, 2) = Rng.Cells(x + 1, 1)
        ShNew.Cells(r, 3) = Rng.Cells(x + 1, 2)
        ShNew.Cells(r, 4) = Rng.Cells(x + 1, 3)
        ShNew.Cells(r, 5) = Rng.Cells(x + 1, 4)
        ShNew.Cells(r, 6) = Rng.Cells(x + 2, 1)
        r = r + 1
    Next x
End Sub

It worked with this data in Sheet1:
CreateDatabase(6).xls
ABCD
11CompanyName
21StreetAddress,City,State,Zipcode
31PhoneNumber
42CompanyName
52StreetAddress,City,State,Zipcode
62PhoneNumber
73CompanyName
83StreetAddress,City,State,Zipcode
93PhoneNumber
104CompanyName
114StreetAddress,City,State,Zipcode
124PhoneNumber
Sheet4
 
Upvote 0
i need to code a macro to do the process quicker, also how would i change the format of the address from |Street address, city, state, zipcode| into |street address|city|state|zipcode| how do i accoplish this.

EDIT: the code you gave did work but on occasions there could be two or more telephone numbers and the format is sckewed
 
Upvote 0
SpringP said:
i need to code a macro to do the process quicker, also how would i change the format of the address from |Street address, city, state, zipcode| into |street address|city|state|zipcode| how do i accoplish this.

Make sure you specify all of your requirements.
 
Upvote 0
Andrew Poulsom, the macro you posted did work. my database has a few missing parts on ocassion. for instance one some doesnt have address but phone number, some has multiple phone numbers. but after a few tweaking the code eventually work.
alot of thanks
 
Upvote 0
ohh yeah theres also one more thing. after the data has been moved the zip codes are changes. since im in the north east we have a lot of zero on the front, for example 07856. when that value is moved to another column it is omited, the data becomes 7856 instead. i know i could format the cell to automatically know that its a zip code and it adds the zero. but when i save the file and open it with another program its not there. i tried changing the column to format as a "text" but then i have to input it manually to hundreds of rows. is there another way to do this?
thanks
 
Upvote 0
First change the TextToColumns line so that column 4 is Text:

Code:
Rng.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _ 
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _ 
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _ 
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 2))

Then change this line:

ShNew.Cells(r, 5) = Rng.Cells(x + 1, 4)

to:

Rng.Cells(x + 1, 4).Copy ShNew.Cells(r, 5)

so that it remains as Text when transferred to the new sheet.
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,665
Members
449,114
Latest member
aides

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