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.
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,267
Office Version
2013
Platform
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?
 

Forum statistics

Threads
1,081,726
Messages
5,360,906
Members
400,602
Latest member
newaqua

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top