Excel Report will not copy results

I have a button on my "Inventory" worksheet that copies items that have "On-Hand" quantity for the number I select.  It pastes the results into the OHReport worksheet.  Everything works just as I want.  

The problem I am having is when I create the same button on the "OHReport" worksheet and run it, I am prompted to enter a quantity, but no results are returned.

Private Sub SelectQtyOH_Click()

Dim OH As String
Dim x As Long
x = 2

OH = InputBox("Enter Search Quantity")
Sheets("Inventory").Select
Do While Cells(x, 1) <> ""
If Cells(x, 7) = OH Then
Worksheets("Inventory").Rows(x).Copy
Worksheets("OHReport").Activate
erow = Sheets("OHReport").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("OHReport").Rows(erow)
End If
Worksheets("Inventory").Activate
x = x + 1
Loop
Application.CutCopyMode = False

Sheets("OHReport").Select

End Sub

Open in new window

Mike OrtherSystems EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
There is a better way of doing this. Use Autofilter to filter the data in column G on Inventory Sheet with the criteria entered in InputBox and then copy the filtered data to the report sheet.
Private Sub SelectQtyOH_Click()
Dim wsData As Worksheet, wsReport As Worksheet
Dim lr As Long, lc As Long, eRow As Long
Dim OH As String

Application.ScreenUpdating = False

Set wsData = ThisWorkbook.Worksheets("Inventory")
Set wsReport = ThisWorkbook.Worksheets("OHReport")

lr = wsData.UsedRange.Rows.Count
lc = wsData.UsedRange.Columns.Count

OH = InputBox("Enter Search Quantity")


wsData.AutoFilterMode = False

With wsData.Rows(1)
    .AutoFilter field:=7, Criteria1:=OH
    If wsData.Range("G1:G" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
        eRow = wsReport.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        wsData.Range(wsData.Cells(2, 1), wsData.Cells(lr, lc)).SpecialCells(xlCellTypeVisible).Copy wsReport.Range("A" & eRow)
    End If
    .AutoFilter
End With
wsReport.Activate
Application.ScreenUpdating = True
End Sub

Open in new window


If that still doesn't work for you, please upload a sample workbook and explain what exactly is not working in there.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike OrtherSystems EngineerAuthor Commented:
Yes, this works much better that my code.  The report is much faster.
Mike OrtherSystems EngineerAuthor Commented:
Thank you so much for this Subodh.  This works beautifully and it is so much faster than what I had
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Mike! Glad it worked as desired.
Thanks for the feedback.
Merry Christmas!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.