+ Reply to Thread
Results 1 to 5 of 5

Select Excel Table values

Hybrid View

  1. #1
    Registered User
    Join Date
    06-17-2011
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    3

    Select Excel Table values

    Hi there,
    I have in one worksheet an excel table, where i have data in four columns,
    lets say Name, Surname, Team, Subteam. I need in other worksheet
    create a header. The header is name and surname of 1 employee
    in one cell. so eg.
    Jan Schmidt T1 ST1
    Ken Hans T1 ST2
    Barbie Doll T2 ST1
    and so on..
    so in first cell i need to have Jan Schmidt, in secod Ken Hans in third Barbie Doll and so on.

    I don't know how to select the table data into a range or somethig,
    where i can iterate on each row and select and output data, i need
    an excel table, because when new employee is added, the macro should
    automatically add new person in header.

    Any help would be appreciated.

    Thanks,
    Kuba

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Select Excel Table values

    Hello Kubas,

    Welcome to the Forum!

    This macro will take the information fro columns "A:B" of "Sheet1" and create headers in row 1 of "Sheet2". Change the sheet names in macro if you need to
    Sub CreateHeaders()
    
      Dim Cell As Range
      Dim DstWks As Worksheet
      Dim Header() As Variant
      Dim I As Long
      Dim Rng As Range
      Dim RngEnd As Range
      Dim SrcWks As Worksheet
      
        Set SrcWks = Worksheets("Sheet1")
        Set DstWks = Worksheets("Sheet2")
        
          Set Rng = SrcWks.Range("A1")
          Set RngEnd = SrcWks.Cells(Rows.Count, Rng.Column).End(xlUp)
          If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = SrcWks.Range(Rng, RngEnd)
          
          For Each Cell In Rng
            ReDim Preserve Header(I)
              Header(I) = Cell & " " & Cell.Offset(0, 1)
            I = I + 1
          Next Cell
          
        DstWks.Range("A1").Resize(1, I).Value = Header
          
    End Sub
    .

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-17-2011
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Select Excel Table values

    Hey,
    thank you for your reply !

    I figured it out too :-)
    In rang you have to just place the table name:
    eg: if table name is tWorkers

    .Range("tWorkers[#Data]") - if you dont want to have the header.

    I have one more question, is there any possibility to get one row in one
    variable, or i need to deal with offsets ?

    Thanks again for help

    Kuba

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Select Excel Table values

    Hello Kuba,

    If you declare a variable as a Range then you can assign an entire row to the variable. You will still need to use the cells property to return or set any individual values.

  5. #5
    Registered User
    Join Date
    06-17-2011
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Select Excel Table values

    HI, sorry for asking, but where can i mark this thread as SOLVED ? i cannot find it anywhere.

    Greets,
    Kuba

+ 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