Create Button That Prompts User To Select Active Cell

eulerddx4

New Member
Joined
Jul 27, 2014
Messages
16
Hello,
I have a macro that uses the active cell to sort through data and fill the acceptable data into three new columns. I wanted to see if someone could help me create a button that prompts the user to select the active cell and then runs through my macro code. This would be very helpful in improving the functionality of my spreadsheet. I'm thinking of using a Msgbox to say something like Please pick the cell you would like to begin sorting. Then the user would be able to click the active cell and the macro would run. Could someone help me write this? I know very little about writing macros and could use your help. Here is my existing code:



Sub mypicker()
rownow=activecell.row
columnnow=activecolumn.column
newrow=9
newcolumn=1
mytime=0
While Cells(rownow,columnnow).Value <> ""
If Cells (rownow,columnnow).Value >18 or (rownow,columnnow).Value <=0 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,column now).Value
newrow=newrow+1
End If
rownow=rownow+1
mytime=mytime+1
Wend
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Something like this:

Rich (BB code):
Sub mypicker()
  Dim rng As Variant

  rng = Application.InputBox("Select Active Cell", Type:=8)
  if rng = False Then Exit Sub ' if cancel is clicked, stop


  rownow = rng.row
  columnnow = rng.column
  newrow=9
  newcolumn=1
  mytime=0
  While Cells(rownow,columnnow).Value <> ""
    If Cells (rownow,columnnow).Value >18 or (rownow,columnnow).Value <=0 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,column now).Value
      newrow=newrow+1
    End If
    rownow=rownow+1
    mytime=mytime+1
  Wend
End Sub
 
Upvote 0
Hi, thanks for your help. For some reason when I add this code I am able to select the cell that I want to start filtering but then I get runtime error 424.
 
Upvote 0
The code, modified as suggested is:


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
 
Upvote 0

Forum statistics

Threads
1,214,428
Messages
6,119,420
Members
448,895
Latest member
omarahmed1

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