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.
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,710
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,118,400
Messages
5,571,906
Members
412,424
Latest member
zolo
Top