VBA Code Help Needed

Lanruner

New Member
Joined
Jul 28, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Afternoon Everyone,

I watched many videos but can't seem to find a solution. I am trying to have a Masterdata sheet that a user could populate the information then press the Macro button to process the information and copy the entire row if it meets the specific condition to the correct tab. I used the If and ElseIf function in VBA. I have 2 issues and wanted to see if anyone can assist. Thank you all in advance and have a great day.

1. When I open the workbook and click on any cell in the Master Data sheet, the VBA is executed and duplicates the same entries in the different tabs, How do I disable that autorun?

2. How do I get this VBA only to copy and paste new items on the other tabs and not the entire MasterData sheet information each time the VBA is executed?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
need to show your code between code tags, its like trying to look at an array of fruit with your eyes closed from 20 feet
 
Upvote 0
Here is the VBA code


Sub Copy_Data()
lastRow = Worksheets("Data").Range("A" & Rows.Count).End(xlUp).Row
For r = 9 To lastRow

If Worksheets("Data").Range("A" & r).Value = "100" The
Worksheets("Data").Rows(r).Copy


Worksheets("ABA1").Activate


lastRowRPT = Worksheets("ABA1").Range("B" & Rows.Count).End(xlUp).Row


Worksheets("ABA1").Range("A" & lastRowRPT + 1).Select


ActiveSheet.Paste





ElseIf Worksheets("Data").Range("A" & r).Value = "200" Then


Worksheets("Data").Rows(r).Copy


Worksheets("ABA2").Activate


lastRowRPT = Worksheets("ABA2").Range("B" & Rows.Count).End(xlUp).Row


Worksheets("ABA2").Range("A" & lastRowRPT + 1).Select


ActiveSheet.Paste





ElseIf Worksheets("Data").Range("A" & r).Value = "300" Then


Worksheets("Data").Rows(r).Copy


Worksheets("ABA3").Activate


lastRowRPT = Worksheets("ABA3").Range("B" & Rows.Count).End(xlUp).Row


Worksheets("ABA3").Range("A" & lastRowRPT + 1).Select


ActiveSheet.Paste





End If





Next r





End Sub
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,607
Members
449,090
Latest member
vivek chauhan

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