How to use a user-selectable range from an InputBox

Sam05

New Member
Joined
Feb 7, 2009
Messages
23
Hi, I'd appreciate some help with the following: I have Sheet1 and Sheet2 of same Workbook. In Sheet1 I have a base list of part numbers. On Sheet2 I have a list of part numbers that vary; more part numbers are added to this list daily. The objective is to identify which new part numbers (out of Sheet2) are NOT in Sheet1 and flag them somehow. I had thought of using an InputBox to ask the user to select the range of new part numbers added to Sheet2, but nothing seems to be assigned to the variable (MyRange) once I select the range. I had something like this:
Dim MyRange as Range
<code>Worksheets("Sheet1").Activate</code>
Set MyRange = Application.InputBox(prompt:="Select range of new part numbers", Type:=8)

After this, I did the comparison looping through the main parts list for each new part number. I know the comparison part works because I replace MyRange with a hard-coded range and it does it fine. Can anyone please point me in the right direction on how to make this work? I'm using 2010 Pro on WinXP SP3.
Thank you.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
If I understand the problem correctly. You tried to loop, using the MyRange variable as a list of values to loop through. The code below worked for me.
Code:
Sub i()
Dim rng As Range, c As Range
Set rng = Application.InputBox("Select range", "Sel", Type:=8)
For Each c In rng
   If c.Value = ActiveSheet.Range("A2").Value Then
 Msg Box "OK"
   End If
Next
End Sub

Were your range selections contiguous cells?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,998
Messages
5,834,808
Members
430,323
Latest member
Regash

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
Top