Input Box for Macro

paulfitz54

New Member
Joined
Dec 30, 2014
Messages
32
Office Version
  1. 2019
Platform
  1. MacOS
Hi,

I have a macro that retrieves a Job Rating of 5 from a drop-down list and places the results in a new sheet.
What I would like to do is have a message asking me for the job rating (1-5), then run the macro to copy the info to another sheet, will an input box work here? and how would I place it into the code below?

Thanks for your assistance in this
Paul

Copy of the code:

Sub JobRating5()
'
' JobRating5 Macro
' Create new worksheet with only personnel with job rating 5
'

'
Selection.AutoFilter
ActiveSheet.Range("$A$1:$G$742").AutoFilter Field:=7, Criteria1:="5"
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
Sheets("Job Rating").Select
Range("A3").Select
ActiveSheet.Range("$A$1:$G$742").AutoFilter Field:=7
Application.CutCopyMode = False
Range("A1").Select
Selection.AutoFilter
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi!

Try:

VBA Code:
Selection.AutoFilter
ActiveSheet.Range("$A$1:$G$742").AutoFilter Field:=7, Criteria1:=InputBox("Job Rating here!")
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
Sheets("Job Rating").Select
Range("A3").Select
ActiveSheet.Range("$A$1:$G$742").AutoFilter Field:=7
Application.CutCopyMode = False
Range("A1").Select
Selection.AutoFilter
End Sub
 
Upvote 0
How about
VBA Code:
Sub paulfitz()
   Dim Ans As Variant
   
   Ans = InputBox("Please enter rating")
   If Ans = "" Then Exit Sub
   With Sheets("Job Rating")
      .Range("A1:G1").AutoFilter 7, Ans
      Sheets.Add , Sheets(.Index)
      .AutoFilter.Range.EntireRow.Copy Range("A1")
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
How about
VBA Code:
Sub paulfitz()
   Dim Ans As Variant
  
   Ans = InputBox("Please enter rating")
   If Ans = "" Then Exit Sub
   With Sheets("Job Rating")
      .Range("A1:G1").AutoFilter 7, Ans
      Sheets.Add , Sheets(.Index)
      .AutoFilter.Range.EntireRow.Copy Range("A1")
      .AutoFilterMode = False
   End With
End Sub


Here are two great lessons!

The first is obviously about how to resolve the doubt. The second is as important as the first, which is like summarizing the writing of a code. This saves time and programming lines.

Thank you very much for that great lesson Mr. Pluff!
 
Upvote 0
Here are two great lessons!

The first is obviously about how to resolve the doubt. The second is as important as the first, which is like summarizing the writing of a code. This saves time and programming lines.

Thank you very much for that great lesson Mr. Pluff!

The writing was summarized from 552 characters to 303, counting the empty spaces.
 
Upvote 0
Hi lads,

Thanks for the quick response, both of your solutions work perfectly

Thanks again
Paul
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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