Consulting

Results 1 to 3 of 3

Thread: Create a List based on Cell Values from multiple Sheets & Columns

  1. #1
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location

    Create a List based on Cell Values from multiple Sheets & Columns

    I’m trying to create a list of every 5th Cell in Row 1 from every sheet whose name begins with “Sheet” starting with Cell B1 of each sheet. I would like to create the list on the sheet called “List”.

    The data on the Sheets are in groups of 5 columns – that’s why I need every 5th cell. Column A has data titles, the data groupings start in Column B.

    There can be several Sheets that begin with the name Sheet and each sheet’s UsedRange can vary in size.

    Any ideas on what code that will copy every 5th cell (starting with B1) in Row 1 as long as there is data in the cells. I would also like to capture the Sheet Name and write that out to the "List" sheet. Column A would have the sheet Name (ie: Sheet1, Sheet2, Sheet3, etc) and Column B would have the Cell Value of cell B2.


    Below is a routine that loops through only those sheets that name begin with the name Sheet and renames it and then write the new name out to the “List” Sheet.


    Can the code in the ********* Box be modified to do the Copy/Paste of the cells needed (every 5th cell in the UsedRange)?

    Thanks for any ideas…

    JimS

    [vba]
    Sub ShtRename()

    Dim sht As Worksheet
    Dim xxx As Variant
    Dim shChanges As Worksheet
    Dim N As Long

    Const strChanges As String = "List"

    Application.ScreenUpdating = False

    Set shChanges = Sheets(strChanges)
    N = 2 'offset that will write sheets that were renamed on the report sheet

    For Each sht In Worksheets
    If sht.Name <> shChanges.Name Then
    xxx = Empty

    If Left(sht.Name, 5) = "Sheet" Then

    *************************************************************
    * On Error Resume Next *
    * xxx = Left(Split(Split(sht.Range("A2").Value, "\\")(1), "\")(0), 25) *
    * On Error GoTo 0 *
    * If Not IsEmpty(xxx) Then sht.Name = xxx *
    *************************************************************


    ' Write new names out to List sheet
    shChanges.Cells(N, "A") = sht.Name
    N = N + 1

    End If
    End If
    Next sht

    Application.ScreenUpdating = True

    End Sub
    [/vba]
    Last edited by JimS; 03-29-2010 at 12:07 PM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post a sample workbook?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location

    Example File

    I have attached a file that has example data. I have manually created what I'm trying to create on the List sheet.

Posting Permissions

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