Macro Input Box not working

eulerddx4

New Member
Joined
Jul 27, 2014
Messages
16
Hello, I have a spreadsheet that I am trying to finish this morning and for some reason I can't get the Input box to work. My macro scans through code and filters data based on whether it is greater than a number, less than a number or the change between cells to the left of the selected cell is greater than a number.

I have added a couple lines of code to prompt the user to select the active cell but for some reason I am getting error code 424 Object required after I select the active cell.

Your help would be greatly appreciated!


Code:
Sub mypicker()
    Dim rng As Variant
    rng = Application.InputBox("Select the first velocity data point that you would like to filter", Type:=8)
    If rng = False Then Exit Sub
    rownow = rng.Row
    columnnow = rng.Column
    newrow = 9
    newcolumn = 1
    mytime = 0
    While Cells(rownow, columnnow).Value <> ""
        If Cells(rownow, columnnow).Value > 18 Or Cells(rownow, columnnow).Value <= 0 Or Abs(Cells(rownow + 1, columnnow - 1) - Cells(rownow, columnnow - 1)) > 0.2 Then
        mya = myb
        Else
            Cells(newrow, newcolumn).Value = mytime
            Cells(newrow, newcolumn + 1).Value = Cells(rownow, columnnow - 1).Value
            Cells(newrow, newcolumn + 4).Value = Cells(rownow, columnnow).Value
            newrow = newrow + 1
        End If
        rownow = rownow + 1
        mytime = mytime + 1
    Wend
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try amending the fifth line to:

Code:
rownow = Range(rng).Row
I'd also remove the "Type:=8". It seems to work better without it for me, even though type 8 is defined as "A cell reference, as a Range object."

Hope this helps,

Chris.
 
Last edited:
Upvote 0
Perhaps like this

Code:
    Dim rng As Range
    Set rng = Application.InputBox("Select the first velocity data point that you would like to filter", Type:=8)
    If rng Is Nothing Then Exit Sub
 
Upvote 0
Ok so I took out

Code:
rownow = Range(rng).Row
and changed that line to my original code

Then I added
Code:
 Dim rng As Range
    Set rng = Application.InputBox("Select the first velocity data point that you would like to filter", Type:=8)
    If rng Is Nothing Then Exit Sub

And it worked perfectly!

Thanks guys!
 
Upvote 0
My final code is below, I didn't remove Type:=8 because I didn't see that until after I started playing with it.

I entered this code and the program works:
Code:
Sub mypicker()
    Dim rng As Range
    Set rng = Application.InputBox("Select the first velocity data point that you would like to filter", Type:=8)
    If rng Is Nothing Then Exit Sub
    rownow = rng.Row
    columnnow = rng.Column
    newrow = 9
    newcolumn = 1
    mytime = 0
    While Cells(rownow, columnnow).Value <> ""
        If Cells(rownow, columnnow).Value > 18 Or Cells(rownow, columnnow).Value <= 0 Or Abs(Cells(rownow + 1, columnnow - 1) - Cells(rownow, columnnow - 1)) > 0.2 Then
        mya = myb
        Else
            Cells(newrow, newcolumn).Value = mytime
            Cells(newrow, newcolumn + 1).Value = Cells(rownow, columnnow - 1).Value
            Cells(newrow, newcolumn + 4).Value = Cells(rownow, columnnow).Value
            newrow = newrow + 1
        End If
        rownow = rownow + 1
        mytime = mytime + 1
    Wend
End Sub

I went back and removed type:=8 and it gives me an error. If this program works with the type:=8 then everything should be ok, right?
 
Upvote 0
I'd imagine so - they both work for me.

My method treats "rng" as a text string, which is why it required "Range(rng)" as opposed to just "rng".

Chris
 
Upvote 0

Forum statistics

Threads
1,216,291
Messages
6,129,911
Members
449,540
Latest member
real_will_smith

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