Hello,
I currently have a macro set up that triggers an Input Box to input a range of dates. Once entered, it scans through the reference sheet and copies and pastes a specified range of cells from any rows containing a date within the input range.
I've been trying to edit this macro to trigger an Input Box that will ask for a specific order number, and once entered it needs to scan two sheets for the order number and copy and paste the same range of cells from any rows containing the order number.
It's the same basic purpose of the current macro, but I can't seem to get the code right to reference multiple sheets. I've researched it for a few days now and I can't find a solution that fits the bill.
Below is the current macro. The copy/paste ranges and destination need to stay the same. I just need to change the input box to search for an exact match (not case-sensitive) and the sheet sources would be "Ontario" and "San Diego" (or Sheet1 and Sheet2). Sheets are in the same workbook.
I currently have a macro set up that triggers an Input Box to input a range of dates. Once entered, it scans through the reference sheet and copies and pastes a specified range of cells from any rows containing a date within the input range.
I've been trying to edit this macro to trigger an Input Box that will ask for a specific order number, and once entered it needs to scan two sheets for the order number and copy and paste the same range of cells from any rows containing the order number.
It's the same basic purpose of the current macro, but I can't seem to get the code right to reference multiple sheets. I've researched it for a few days now and I can't find a solution that fits the bill.
Below is the current macro. The copy/paste ranges and destination need to stay the same. I just need to change the input box to search for an exact match (not case-sensitive) and the sheet sources would be "Ontario" and "San Diego" (or Sheet1 and Sheet2). Sheets are in the same workbook.
Code:
Sub Ontario_Releases()Dim startdate As Date, enddate As Date
Dim rng As Range, destRow As Long
Dim shtSrc As Worksheet, shtDest As Worksheet
Dim c As Range
Set shtSrc = Sheets("Ontario")
Set shtDest = Sheets("RELEASE SCHEDULE")
destRow = 3
startdate = CDate(InputBox("Beginning Date"))
enddate = CDate(InputBox("End Date"))
Set rng = Application.Intersect(shtSrc.Range("J:Y"), shtSrc.UsedRange)
For Each c In rng.Cells
If c.Value >= startdate And c.Value <= enddate Then
Sheet1.Range("B" & c.Row).Copy
shtDest.Cells(destRow, 4).PasteSpecial Paste:=xlPasteValues
Sheet1.Range("D" & c.Row, "G" & c.Row).Copy
shtDest.Cells(destRow, 5).PasteSpecial Paste:=xlPasteValues
Sheet1.Range("Z" & c.Row).Copy
shtDest.Cells(destRow, 11).PasteSpecial Paste:=xlPasteValues
Range(c, c.Offset(0, 1)).Copy
shtDest.Cells(destRow, 9).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
destRow = destRow + 1
End If
Next
End Sub