ExcelTesting
New Member
- Joined
- Mar 5, 2019
- Messages
- 1
I have two issues.
1. I would like to be to run two If statemetns
If Audit area Combobox is Blank return all values and run the if statement for the report range
or
If Audit Area combobox has a value return that value and run the if statement for the report range
2. Once that is done I would to add a new worksheet name that worksheet the value of the report range combo box and then copy and paste the results of 1 above. I also would like the new sheet to keep the formatting of the source data
Here is my code
Private Sub PBCReportButton_Click()
'Runs PBC Due Date Report'
Dim Audit_Area As String
Audit_Area = Trim(AuditAreaCB.Text)
Dim Report_Range As String
Report_Range = Trim(ReportRangeCb.Text)
lastrow = Worksheets("PBC View All").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("PBC Report").Rows("2:" & Rows.Count).ClearContents
For I = 2 To lastrow
If Worksheets("PBC View All").Cells(I, 11).Value = Audit_Area And Worksheets("PBC View All").Cells(I, 5).Value = Report_Range Then
Worksheets("PBC View All").Rows(I).Copy
Worksheets("PBC Report").Activate
b = Worksheets("PBC Report").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("PBC Report").Cells(b + 1, 1).Select
ActiveSheet.Paste
End If
Next
Application.CutCopyMode = False
Worksheets("PBC View All").Activate
Worksheets("PBC View All").Cells(1, 1).Select
End Sub
1. I would like to be to run two If statemetns
If Audit area Combobox is Blank return all values and run the if statement for the report range
or
If Audit Area combobox has a value return that value and run the if statement for the report range
2. Once that is done I would to add a new worksheet name that worksheet the value of the report range combo box and then copy and paste the results of 1 above. I also would like the new sheet to keep the formatting of the source data
Here is my code
Private Sub PBCReportButton_Click()
'Runs PBC Due Date Report'
Dim Audit_Area As String
Audit_Area = Trim(AuditAreaCB.Text)
Dim Report_Range As String
Report_Range = Trim(ReportRangeCb.Text)
lastrow = Worksheets("PBC View All").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("PBC Report").Rows("2:" & Rows.Count).ClearContents
For I = 2 To lastrow
If Worksheets("PBC View All").Cells(I, 11).Value = Audit_Area And Worksheets("PBC View All").Cells(I, 5).Value = Report_Range Then
Worksheets("PBC View All").Rows(I).Copy
Worksheets("PBC Report").Activate
b = Worksheets("PBC Report").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("PBC Report").Cells(b + 1, 1).Select
ActiveSheet.Paste
End If
Next
Application.CutCopyMode = False
Worksheets("PBC View All").Activate
Worksheets("PBC View All").Cells(1, 1).Select
End Sub