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
 

iliace

Well-known Member
Joined
Jan 15, 2008
Messages
3,531
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
 

eulerddx4

New Member
Joined
Jul 27, 2014
Messages
16
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.
 

eulerddx4

New Member
Joined
Jul 27, 2014
Messages
16
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
 

Forum statistics

Threads
1,082,259
Messages
5,364,100
Members
400,779
Latest member
lumers

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top