Copy row based on criteria from one sheet to another

roy00a4

New Member
Joined
Mar 15, 2016
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Dear Forumers,

I can't tell you all how happy I am to be a part of this forum and such great minds. I am not new to excel but to VBA. I would request all to help me with a macro that I am unable to create using record macro. I know thats very basic, but I am new to VBA and eager to learn.

I have a work book with two sheets. Sheet 1 - Master, Sheet 2 - Dump Filter. What I am trying to do is .. I get a data extract to generate a report. I have finished all formulations and everything else. In sheet "Dump Filter" I paste the data extract from Column B to Column BT. Doing this column A generates "Not In Master" when it doesn't find a data in the "Master" sheet.

I am trying to record a macro where in the rows with the criteria "Not In Master" from column A would be copied to sheet "Master". For sheet "Dump Filter" the criteria is in Column A and the data would be copied from colB to colBT where ever colA has "Not In Master". Then these copied fields would be pasted in the next blank row of sheet "Master" from colD to colBV.

I hope I am able to make sense of what I am trying to achieve. Any help is really appreciated and would be ever grateful..

Thank you in advance for all who helps and suggest.

Regards
roy00a4
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
[color=darkblue]Sub[/color] Filter_Not_In_Master()
    
    [color=green]'This macro assumes that your first row of data is a header row.[/color]
    [color=green]'The rows with the criteria "Not In Master" from column A would be copied to sheet "Master".[/color]
    [color=green]'For sheet "Dump Filter" the criteria is in Column A and the data would be copied from colB[/color]
    [color=green]'to colBT where ever colA has "Not In Master". Then these copied fields would be pasted in[/color]
    [color=green]'the next blank row of sheet "Master" from colD to colBV.[/color]
        
    [color=green]'Variables used by the macro[/color]
    [color=darkblue]Dim[/color] shSource [color=darkblue]As[/color] Worksheet
    [color=darkblue]Dim[/color] shDestination [color=darkblue]As[/color] Worksheet
    
    [color=darkblue]Set[/color] shSource = Sheets("Dump Filter")    [color=green]'Source worksheet[/color]
    [color=darkblue]Set[/color] shDestination = Sheets("Master")    [color=green]'Destination worksheet[/color]
    
    Application.ScreenUpdating = [color=darkblue]False[/color]
                
    [color=green]'Autofilter column A for "Not In Master"[/color]
    shSource.UsedRange.AutoFilter Field:=1, Criteria1:="Not In Master"
    
    [color=green]' Copy filtered data from columns B:BT[/color]
    shSource.UsedRange.Columns("B:BT").Offset(1).Copy
    
    [color=green]'Paste the filtered data to Sheet "Master"  column D[/color]
    shDestination.Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
    Application.CutCopyMode = [color=darkblue]False[/color]
    
    [color=green]'Clean up[/color]
    shSource.AutoFilterMode = [color=darkblue]False[/color]
    Application.Goto shDestination.Range("A1")
    Application.ScreenUpdating = [color=darkblue]True[/color]
    MsgBox "Completed"
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Hi AlphaFrog,


I cant thank you enough. You have saved me from 5 days of hell. The code runs like a charm. AMAZING !!!!


Thank you so much for your help


Regards
roy00a4
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top