Results 1 to 3 of 3

Auto copy specific data from sheet to antoher sheet under few condition

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-09-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    212

    Auto copy specific data from sheet to antoher sheet under few condition

    Current, VBA code manage to copy data from sheet [Template] to sheet [All] when run the macros.

    My issues are:-

    [refer to file attached]
    1. How to auto run the macros when re-select drop down list at column C4 or before save the file? And there is duplicate data copy over to sheet [All]

    2. How to ensure all data from sheet [Template] to sheet [All] doesn't over-copy? Result wanted may refer to sheet [Example].

    Sub Search_Copy()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim HeaderCells As Range, Hdr As Range, hdrFIND As Range
    
    Application.ScreenUpdating = False                          'speed things up
    Set ws1 = Sheets("Template")                 'Define name of worksheets
    Set ws2 = Sheets("All")
    
    With ws1
        'Set HeaderCells = .Rows(7).SpecialCells(xlConstants)    'a collection of the headers on ws1
        
        Set HeaderCells = .Range("A7", .Cells(7, .Columns.Count).End(xlToLeft))
    
        On Error Resume Next                                    'skip columns where header isn't found on ws2
        For Each Hdr In HeaderCells                             'process one header cell at a time
            Set hdrFIND = ws2.Rows(1).Find(Hdr.Text, LookIn:=xlValues, LookAt:=xlWhole)     'try to find match on ws2
            If Not hdrFIND Is Nothing Then                      'if found, copy to that column on ws2
                .Range(Hdr.Offset(1), .Cells(.Rows.Count, Hdr.Column)).Copy ws2.Cells(Rows.Count, hdrFIND.Column).End(xlUp).Offset(1)
            End If
        Next Hdr
    End With
    
    Application.ScreenUpdating = True                           'back to normal
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copy specific data from Monthly auto generated workbook to master sheet
    By onbeillp111 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-26-2014, 12:25 PM
  2. Replies: 1
    Last Post: 09-17-2013, 01:38 PM
  3. Need VBA to auto copy data from one sheet to specific on based of Staus
    By nadeemjadoon in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-04-2013, 12:25 PM
  4. [SOLVED] Copy and paste data from sheet 2 to sheet 1 based on specific criteria on sheet 1
    By VBADUD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2012, 04:18 AM
  5. auto copy from 1 sheet to other if condition met
    By starlover123 in forum Excel General
    Replies: 3
    Last Post: 07-04-2009, 09:25 AM

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