Results 1 to 7 of 7

Macro/VBA need help to copy the mathces to the master worksheet

Threaded View

maytam Macro/VBA need help to copy... 03-13-2014, 02:36 AM
Tinbendr Re: Macro/VBA need help to... 03-13-2014, 08:13 PM
maytam Re: Macro/VBA need help to... 03-14-2014, 01:36 AM
Tinbendr Re: Macro/VBA need help to... 03-14-2014, 08:52 AM
maytam Re: Macro/VBA need help to... 03-16-2014, 10:31 PM
Tinbendr Re: Macro/VBA need help to... 03-17-2014, 09:08 AM
maytam Re: Macro/VBA need help to... 03-18-2014, 04:41 AM
  1. #1
    Registered User
    Join Date
    10-24-2013
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    20

    Question Macro/VBA need help to copy the mathces to the master worksheet

    Hello
    I found the below VBA code to find the matches, unfortunately, it copied to the wrong place. Instead I need the matches, copy its corresponding value to column D from "Data" worksheet to the "Master" worksheet. For example, in "Data" worksheet the Code ABC is 3534, it should then copy only the value to the "Master" worksheet's D column. Please help.

    Master worksheet
    A B C D E
    Code Orange Apple Total
    ABC 123.00 567.00 690.00
    DEF 57,974.34 - 57,974.34
    GHI 58,490.00 8.00 58,498.00
    MNO 4.00 571.00 575.00
    LOK 7,604.00 899.00 8,503.00
    MKO - - -
    MIL 1,674.00 - 1,674.00
    FRE 13,415.12 - 13,415.12

    Data worksheet
    Code Total
    ABC 3534
    DEF 12276
    GHI 3248
    IN0019 11726
    IN0020 1984
    LOK 55
    MIL 1472
    MNO 10384
    Grand Total 121047

    Option Explicit 
    
    Private Const MASTER_B_COL_IDX As Integer = 2 
    Private Const DATA_A_COL_IDX As Integer = 1 
    
    Public Sub FindMatchingData() 
     Dim MasterWrkSh As Worksheet 
     Dim MasterColCount As Integer 
     Dim MasterRowCount As Long 
     Dim MasterCol As Integer 
     Dim MasterRow As Long 
     Dim DataWrkSh As Worksheet 
     Dim DataColCount As Integer 
     Dim DataRowCount As Long 
     Dim DataRow As Long 
     Dim CopyData As Integer 
     Dim PrintData As Integer 
     Dim Data() As Variant 
    
     Set MasterWrkSh = Sheets("Master") 
     Set DataWrkSh = Sheets("Data") 
    
     MasterColCount = MasterWrkSh.UsedRange.Columns.Count 
     MasterRowCount = MasterWrkSh.UsedRange.Rows.Count 
     DataColCount = DataWrkSh.UsedRange.Columns.Count 
     DataRowCount = DataWrkSh.UsedRange.Rows.Count 
    
     ReDim Data(DataColCount, 0) 
    
     For MasterRow = 1 To MasterRowCount 
    
     Application.StatusBar = Format(MasterRow / MasterRowCount, "0 %") 
     DoEvents 
     For DataRow = 1 To DataRowCount 
    
     If MasterWrkSh.Cells(MasterRow, MASTER_B_COL_IDX) = _ 
     DataWrkSh.Cells(DataRow, DATA_A_COL_IDX) Then 
     ReDim Preserve Data(DataColCount, UBound(Data, 2) + 1) 
     Data(0, UBound(Data, 2)) = MasterRow 
     For CopyData = 1 To DataColCount 
     Data(CopyData, UBound(Data, 2)) = DataWrkSh.Cells(DataRow, CopyData) 
     Next 
    
     Exit For 
     End If 
     Next 
     Next 
    
     For PrintData = 1 To UBound(Data, 2) 
     For MasterCol = 1 To UBound(Data, 1) 
     MasterWrkSh.Cells(Data(0, PrintData), MasterCol + MasterColCount) = Data(MasterCol, PrintData) 
     Next 
     Next 
    
    Set DataWrkSh = Nothing 
    Set MasterWrkSh = Nothing 
    
    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. Replies: 9
    Last Post: 01-16-2014, 11:28 AM
  2. Replies: 3
    Last Post: 02-04-2013, 06:00 PM
  3. Drop Down List to Copy Entire Contents of Worksheet into Master Worksheet
    By mrmartin in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-14-2011, 10:54 PM
  4. Macro to copy data from worksheet (name changes daily) to master workbook
    By bshelman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-10-2008, 08:52 AM
  5. Copy an existing worksheet and carry totals to a master worksheet
    By adore_r in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2008, 12:02 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