+ Reply to Thread
Results 1 to 9 of 9

Transpose Macro

Hybrid View

b50 Transpose Macro 03-23-2010, 10:52 AM
mdbct Re: Transpose Macro 03-23-2010, 10:57 AM
b50 Re: Transpose Macro 03-23-2010, 11:11 AM
JBeaucaire Re: Transpose Macro 03-23-2010, 11:28 AM
b50 Re: Transpose Macro 03-23-2010, 11:34 AM
JBeaucaire Re: Transpose Macro 03-23-2010, 11:38 AM
b50 Re: Transpose Macro 03-23-2010, 11:45 AM
mdbct Re: Transpose Macro 03-23-2010, 11:51 AM
b50 Re: Transpose Macro 03-23-2010, 12:06 PM
  1. #1
    Registered User
    Join Date
    11-18-2008
    Location
    USA
    Posts
    54

    Transpose Macro

    Hey all,

    I don't know if it is possible to write a macro for this or not.

    The data I have is ordered as follows:

    Name
    Company
    Phone
    Email

    Name
    Company
    Phone

    Name
    Company
    Phone
    Email


    Note: There aren't spaces, it was just hard to read with the it all together.

    The data continues in this manner for just over 1000 people, but randomly throughout the data there are some people who I don't have a phone number or email address.

    I need to have this data organized in the following manner:

    Name, Company, Phone, Email.

    I tried using this script, and it worked except for the fact that I didn't know how to edit it for the cases when there isn't an email address or phone number.


    Sub ChrisMacro()
    Dim rng As Range
    Dim i As Long
    Dim j As Long
    Set rng = Cells(Rows.Count, 1).End(xlUp)
    j = 1
    For i = 1 To rng.Row Step 10
    Cells(j, "B").Resize(1, 5).Value = _
    Application.transpose(Cells(i, "A").Resize(6, 1))
    j = j + 1
    Next
    End Sub

    As I said I am not sure if this is possible, but any help would be greatly appreciated.

    Thanks!
    Last edited by b50; 03-23-2010 at 10:54 AM.

  2. #2
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: Transpose Macro

    Please post a sample workbook so we can see your actual structure.

  3. #3
    Registered User
    Join Date
    11-18-2008
    Location
    USA
    Posts
    54

    Re: Transpose Macro

    Here is something I threw together, this isn't exactly what the data looks like, but it shows how the data looks.
    Attached Files Attached Files

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Transpose Macro

    That's a really bad sample workbook. Most company names and phone numbers aren't considered sensitive data, and email addresses can be masked pretty simply.

    To do data validation, you'll need to provide some assurances of data integrity. Email addresses are easy...pretty much any text string with an @ in it is an email address, pretty safe assumption.

    But phone numbers get stored many ways. Can you verify that every phone number has dashes in it or parentheses? Can you verify your name fields do not?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Registered User
    Join Date
    11-18-2008
    Location
    USA
    Posts
    54

    Re: Transpose Macro

    I apologize I didn't even think about you wanting to know how the data was formatted.

    I attached another spreadsheet with exactly how the data is formatted.

    The name and company fields are just letters.
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Transpose Macro

    I also noticed some examples of a name and phone number only. How does a macro tell the difference between a text string that is a human name and one that is a business name?

  7. #7
    Registered User
    Join Date
    11-18-2008
    Location
    USA
    Posts
    54

    Re: Transpose Macro

    I don't know how it would. Thats why I'm here.

    THe only way that I can think of telling if something is a company is if it appears above an email address or telephone number.

  8. #8
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: Transpose Macro

    As long as there is a First Last Followed by the Company the following will work:

    I didn't see any Names without a Company in the sheet I was working with.

    Sub transpose()
    Dim i As Long, tRow As Long, newName As String
    
    Cells(1, 4) = "Name"
    Cells(1, 5) = "Company"
    Cells(1, 6) = "Phone"
    Cells(1, 7) = "EMail"
    
    i = 1
    tRow = 2
    Do Until Cells(i, 1) = ""
        Cells(tRow, 4) = Cells(i, 1)
        i = i + 1
        Cells(tRow, 5) = Cells(i, 1)
        i = i + 1
    If Left(Cells(i, 1), 3) = "Tel" Then
        Cells(tRow, 6) = Cells(i, 1)
        i = i + 1
    End If
    If Left(Cells(i, 1), 5) = "Email" Then
        Cells(tRow, 7) = Cells(i, 1)
        i = i + 1
    End If
    tRow = tRow + 1
    
    Loop
    End Sub
    Last edited by mdbct; 03-23-2010 at 11:53 AM.

  9. #9
    Registered User
    Join Date
    11-18-2008
    Location
    USA
    Posts
    54

    Re: Transpose Macro

    Worked perfect Thank you very very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1