Copy and Paste and If Statement Issues

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
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,223,886
Messages
6,175,194
Members
452,616
Latest member
intern444

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