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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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?
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,812
Members
449,048
Latest member
greyangel23

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