VBA - Copy Row Data to Separate Sheet when Multiple Criteria is Met

Rebeccah83

New Member
Joined
Jun 30, 2016
Messages
7
I am building a VBA to generate a report but have never built a VBA before.
User enters:
Date From (B3)
Date to (D3)
Employee (F3) *Enters "All Employees" if wishing to include all employee data

They hit the "Submit" VBA button and...the data populates beginning in A12 of the active sheet.

Data is pulled from worksheet labeled "LV Daily Employee Data".
Dates are held in column B (which I have named "Date")
Employees are in column C (named "Employee")
The full range of the data needing to be reviewed/copied is named "DailyData".

I figure the old data will need to be cleared every time. So, here is what I have so far:
Private sub Submit_Click()
ActiveSheet.Range("A12","AU1000").ClearContents
EndSub

Assistance on the rest would be much appreciated.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hello. You've stated what you have but haven't described what you need. It'll also help to attach the workbook when you describe what it is you specifically need.
 
Upvote 0
Rebeccah83,
You have a good start. When you write down the steps then all you need to do is write a Sub or Function for each step. I would use a named range for the data. To me it is easier to address later.
Select the cell for the date (you said B3).
In the Address Bar (Where the current cell address is being displayed on the left of your screen) type a meaningful name and hit enter. Now you can address that cell in your code by the name you gave it. You can modify, delete, add names under the Formulas Tab - Name Manager. In your code you may have Range("DateFrom").Value and Range("DateTo").Value.

So you need to define the result a little better. What data and how is it organized on the other sheet? Is it organized by date, name, or something else?

There are a thousand good tutorials on the internet. Once you have your steps written down you can start following tutorials to help you write the routines. When you get stuck on something particular, post it here.

We'll gladly help, but need more to go on.
 
Upvote 0
Apologies for not being clear. Full spreadsheet here.

What I want is to pull the data in the rows from this sheet (LV Daily Employee Data).
The rows should display in this sheet (Employee Report) , starting at A12.

If F3 = "All Employees", then all rows where (criteria1) the value in "Date" is >= B3 AND (criteria2) the value in "Date" is <= D3 should display.

If F3 <> "All Employees", then all rows where (criteria1) the value in "Employee" matches F3 AND (criteria2) the value in "Date" is >= B3 AND (criteria3) the value in "Date" is <= D3 should display.
 
Upvote 0
Here is what I have so far. I keep getting a compile error - Sub or Function not defined.

Private Sub Submit_Click()
ActiveSheet.Range("A12", "AU1000").ClearContents
If ActiveSheet.Range("F3") = "All Employees" Then
If Worksheet("LV Daily Employee Data").Range("Date") >= Worksheet("Employee Report").Range("B3") Then
If Worksheet("LV Daily Employee Data").Range("Date") <= Worksheet("Employee Report").Range("D3") Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy

Worksheet("Employee Report").Range("A12", "AU:1000").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
Worksheet("LV Daily Employee Data").Select
End If
End If
Else
If Worksheet("LV Daily Employee Data").Range("Employee") = Worksheet("Employee Report").Range("F3") Then
If Worksheet("LV Daily Employee Data").Range("Date") >= Worksheet("Employee Report").Range("B3") Then
If Worksheet("LV Daily Employee Data").Range("Date") <= Worksheet("Employee Report").Range("D3") Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy

Worksheet("Employee Report").Range("A12", "AU:1000").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
Worksheet("LV Daily Employee Data").Select
End If
End If
End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,020
Members
449,480
Latest member
yesitisasport

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