Consulting

Results 1 to 4 of 4

Thread: Gathering sheet names and displaying them in a specific sheet column

  1. #1
    VBAX Regular
    Joined
    Aug 2016
    Posts
    13
    Location

    Gathering sheet names and displaying them in a specific sheet column

    Hi,

    I want to display my results in a Cell/column in a specific sheet(test) on a button click.

    I have this piece of code below. Which is giving the names of all visible sheets but i need them to go to a specific place in that sheet.

        Dim ws As Worksheet, ws1 As Worksheet
        Set ws1 = Sheets("Test")
        i = 1
    
    
        ws1.Columns(1).Insert
        For Each ws In ThisWorkbook.Worksheets
            If ws.Visible = xlSheetVisible Then
                ws1.Cells(i, 1) = ws.Name
                i = i + 1
    
    
    
    
            End If
        Next ws
    Any help would be much appreciated.

    Many thanks
    Last edited by LePig; 09-01-2016 at 04:02 AM.

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    specify 'specific place' specifically please.
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    They already go in a specific place (the top of an newly inserted column on a sheet called "Test").
    It's quite hard to give you a solution if we don't know where that specific place is.
    Let's say it's cell C33 and below on sheet "Test", then:
    Dim ws As Worksheet, destn As Range
    Set destn = Sheets("Test").Range("C33")
    For Each ws In ThisWorkbook.Worksheets
        If ws.Visible = xlSheetVisible Then
            destn.Value = ws.Name
            Set destn = destn.Offset(1)
        End If
    Next ws
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    I looks like they start to fill in A1 on "Test", then A2, A3, etc.


    ws1.Cells(i, 1) = ws.Name
    That's a 'specific place'

    Change the line if you want them to fill in somewhere else
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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