We help IT Professionals succeed at work.

Excel Report will not copy results

221 Views
Last Modified: 2018-12-21
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

Comment
Watch Question

Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Mike OrtherSystems Engineer

Author

Commented:
Yes, this works much better that my code.  The report is much faster.
Mike OrtherSystems Engineer

Author

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 Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
You're welcome Mike! Glad it worked as desired.
Thanks for the feedback.
Merry Christmas!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions