Results 1 to 5 of 5

for each sheet with first 3 char matching variable, copy column C to Target sheet unless..

Threaded View

Spyderz for each sheet with first 3... 11-10-2012, 06:43 PM
mike7952 Re: for each sheet with first... 11-10-2012, 07:36 PM
jindon Re: for each sheet with first... 11-10-2012, 08:49 PM
Spyderz Re: for each sheet with first... 11-11-2012, 02:36 AM
mike7952 Re: for each sheet with first... 11-11-2012, 08:17 AM
  1. #1
    Registered User
    Join Date
    10-14-2011
    Location
    chesapeake, va
    MS-Off Ver
    Excel 2007
    Posts
    59

    for each sheet with first 3 char matching variable, copy column C to Target sheet unless..

    So I've been trying to Copy Column C from Each Sheet that starts with "STU" to Sheet("Target") starting at "A2", there will be other sheets not starting with "STU" but if add additional sheets starting with "STU", I want to enter only the new info to the next blank column stating at row 2.. I'm using the sheet names as the A2 header, then filling in the info under the header, A3.
    I've manage to copy the code, use only the sheets i wanted, but it i ran the code a secong time, it just adds all the sheets again, I've tried using application.worksheetfunction.match, tried coping sheet names first, then check cell values against sheets, but am unable to figure it out..

    here's the code I've butcher, please don't laugh too hard, I'm trying
    Sub Pull_Data()
        'MsgBox "Please Be Patient"
        Dim Cell As Variant
        Dim mRng As Range
        Dim J As Integer
        Dim wsSource As Worksheet
        Dim wsDest As Worksheet
        Dim rng As Range
        Dim drng As Range
    
        Dim strSourceFile As String
        Dim strSourceDirectory As String
        Dim counter As Long
        Dim i As Long
        
        
        Set wsDest = Sheets("TARGET")
       Count = ThisWorkbook.Worksheets.Count
       
     For Each sh In Sheets
     SName = "STU"
     If Left$(sh.Name, 3) = SName Then
     CName = sh.Name
     Set mRng = Sheets("Target").Range("A2:AA2")
        For Each Cell In mRng
            If Cell.Value = "" Then
            Cell.Value = CName
            GoTo 4
            Else
            
           
           
            With Sheets(CName)
                    With Application
                        .ScreenUpdating = False
                        .EnableEvents = False
                    End With
                    .Activate
                    .Select
            Set wsSource = ActiveSheet
            Set drng = wsDest.Range("A3")
    
                    
    1
            Do While drng.Value <> ""
              Set drng = drng.Offset(0, 1)
              GoTo 1
              Loop
              drng.Offset(-1, 0).Value = ActiveSheet.Name
                f = 1
    2
                Do While ActiveSheet.Range("C" & f).Value = ""
                    f = f + 1
                    GoTo 2
                    Loop
                
                    firstrow = Range("C" & f)
                    'MsgBox (firstrow.Value)
                
                    lastrow = Cells(Rows.Count, "A").End(xlUp).Row
                    For i = f To lastrow
                    
                        For Each rng In Range("C" & i)
                        drng.Value = rng.Value
    
                        Next rng
                        Set drng = drng.Offset(1)
                   Next i
            End With
    3
           
    
        End If
        Next Cell
    
    
     Else
    
     End If
    4
     Next sh
    
    Sheets("Target").Activate
       
    End Sub
    there's other code, all under workbook, but it doesn't function
    and heres the workbook
    StuTest V1.xlsm
    Last edited by Spyderz; 11-11-2012 at 02:36 AM.

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