+ Reply to Thread
Results 1 to 9 of 9

VBA for Copy/Paste-Transpose for ranges that vary in size

  1. #1
    Registered User
    Join Date
    03-06-2017
    Location
    Kalamazoo, MI
    MS-Off Ver
    2016
    Posts
    5

    VBA for Copy/Paste-Transpose for ranges that vary in size

    Hello,
    I have a list of data with 6000 names and various pieces of information about that individual.

    John Smith
    Company A
    555-555-1234
    555-555-2000
    [email protected]
    MikeJones
    CompanyB
    555-123-4567
    [email protected]


    My goal here is to take the above information and put it into table format. The issue that I'm having is that:
    1) I'm a novice to macros
    2) My amount of fields for a given individual isn't always the same. In the above example John Smith has 5 fields and Mike Jones has 4 fields. This results in a phone number being the 4th piece of information for John Smith and an email address for Mike Jones.

    Thanks in advance for the help!!

    How do I go about making a macro that copies the indivuals information into a table where all fields are under the appropriate table column?
    Attached Files Attached Files
    Last edited by j611obrien; 03-06-2017 at 01:29 PM.

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: VBA for Copy/Paste-Transpose for ranges that vary in size

    Can you upload sample of your workbook?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Registered User
    Join Date
    03-06-2017
    Location
    Kalamazoo, MI
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA for Copy/Paste-Transpose for ranges that vary in size

    Done! You'll notice that some of the individuals (highlighted in yellow) have a "show my listings", yet others do not. So some names have 7 lines of information, others have 8.
    " ,

  4. #4
    Registered User
    Join Date
    03-06-2017
    Location
    Kalamazoo, MI
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA for Copy/Paste-Transpose for ranges that vary in size

    Quote Originally Posted by YasserKhalil View Post
    Can you upload sample of your workbook?
    Done! You'll notice that some of the individuals (highlighted in yellow) have a "show my listings", yet others do not. So some names have 7 lines of information, others have 8.
    " ,

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: VBA for Copy/Paste-Transpose for ranges that vary in size

    Do you need to deal with sheet1?
    It would be easier if the first block starts with colored cell as you attached but I think you put these colors for illustration purposes

  6. #6
    Registered User
    Join Date
    03-06-2017
    Location
    Kalamazoo, MI
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA for Copy/Paste-Transpose for ranges that vary in size

    Quote Originally Posted by YasserKhalil View Post
    Do you need to deal with sheet1?
    It would be easier if the first block starts with colored cell as you attached but I think you put these colors for illustration purposes
    Whatever is easiest. Correct, I just highlighted the cells as a visual.

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: VBA for Copy/Paste-Transpose for ranges that vary in size

    Does this help?

    Please Login or Register  to view this content.
    Last edited by JOHN H. DAVIS; 03-06-2017 at 03:37 PM.

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA for Copy/Paste-Transpose for ranges that vary in size

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  9. #9
    Registered User
    Join Date
    03-06-2017
    Location
    Kalamazoo, MI
    MS-Off Ver
    2016
    Posts
    5

    Re: VBA for Copy/Paste-Transpose for ranges that vary in size

    Hello,
    My apologies for the delayed response. Your macro works about 1/2 the time. Sometimes I get a "Run-time Error '9': Subscript out of range". When I step into the VBA the MyArray(Count, Pos) = T is highlighted. So I assume it's getting hung up there. Can you assist? Thanks.


    Sub SWMRIC()
    '
    ' SWMRIC Macro
    '

    With ActiveSheet.UsedRange
    SR = .Row
    SC = .Column
    LR = .Rows(UBound(.Value)).Row
    LC = .Columns(UBound(.Value, 2)).Column
    End With

    'Write Titles
    Titles = Array("Name", "Company", "Tel.1", "Tel.2", "Email", "See.1", "See.2", "Member Of:")
    Range("B2:I2").Value = Titles
    'How Many Entries do we have?
    Entries = Application.WorksheetFunction.CountIf(Range("A:A"), "*@*")

    ReDim MyArray(Entries - 1, 7)

    'Read Data into VBA
    InputA = Range(Cells(SR, SC), Cells(LR, SC)).Value

    StartPos = 1

    'We need to do this for every Entry.
    For Count = 0 To Entries - 1

    Pos = 0
    TFlag = 0

    EndPos = Range(Cells(StartPos + 1, 1), Cells(LR, 1)).Find("Member Of ", LookIn:=xlValues, Lookat:=xlPart).Row - 1

    'We need to do this for every line of the entry.

    For Count2 = StartPos To EndPos
    T = InputA(Count2, 1)
    If InStr(T, "@") > 0 Then MyArray(Count, 4) = T: GoTo Skip
    If Left(T, 1) = "(" Then MyArray(Count, 2 + TFlag) = T: TFlag = 1: GoTo Skip
    If Left(T, 9) = "Member of" Then MyArray(Count, 7) = T: GoTo Skip
    MyArray(Count, Pos) = T: Pos = Pos + 1: If Pos = 2 Then Pos = 5

    Skip:

    Next

    StartPos = EndPos + 1
    Next

    'Save The Sorted Data to Spreadsheet
    Range("B3:I" & Entries + 2).Value = MyArray
    End Sub


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Dashboard Theory: Presenting Numbers That Vary in Size
    By The_Snook in forum Excel General
    Replies: 2
    Last Post: 10-13-2016, 10:37 AM
  2. copy and paste with transpose
    By atwy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2015, 10:24 AM
  3. copy paste transpose
    By alexanderdeluna in forum Excel General
    Replies: 2
    Last Post: 09-19-2013, 06:32 PM
  4. Copy from Array in ActiveWorkbook to ThisWorkbook; Transpose copy, Offset Paste
    By sbradley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2013, 05:17 PM
  5. Transpose without copy and paste
    By SSS777 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-10-2013, 02:24 AM
  6. Subtotals in a range that could vary in size
    By yobrokerboy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2005, 02:05 AM

Tags for this Thread

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