I need help correcting a Macro. I have a sample spreadsheet that I can attach, but do not see how to do that.
I want the user to be able to press the "Clear Form" button on any recipe in a recipe pricing spreadsheet and clear the individual recipe. I recorded the following macro with relative cell references so that I can use one macro for all recipes. The sample spreadsheet only has 2 recipe sections, but the actual spreadsheet where I will be using this has 100.
Sub ClearRecipe()
'
' ClearRecipe Macro
'
'
ActiveCell.Offset(0, 1).Range("A1:C1").Select
Selection.ClearContents
ActiveCell.Offset(3, -1).Range("A1:D16").Select
Selection.ClearContents
ActiveCell.Offset(18, 3).Range("A1:A2").Select
Selection.ClearContents
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.ClearContents
ActiveCell.Offset(-20, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(5, -1).Range("A1").Select
End Sub
This works as long as the user knows to click the Recipe # before clicking the "Clear Form" button.
I want the user to be able to click the "Clear Form" button no matter where the cursor is located, so I added the following code to ask for an input cell, hoping it would then start the relative references later in the macro with the user input. It did not work.
Sub ClearRecipe_inputRange()
'
' ClearRecipe_inputRange Macro
'
'
Dim inputRange As Range
On Error Resume Next
Set inputRange = Application.InputBox("Click Recipe # to delete.", Type:=8)
On Error GoTo 0
If Nothing Is inputRange Then
MsgBox "No Recipe # Chosen."
Else
MsgBox "Recipe " & inputRange.Value & " was chosen."
End If
ActiveCell.Offset(0, 1).Range("A1:C1").Select
Selection.ClearContents
ActiveCell.Offset(3, -1).Range("A1:C16").Select
Selection.ClearContents
ActiveCell.Offset(18, 3).Range("A1:A2").Select
Selection.ClearContents
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.ClearContents
ActiveCell.Offset(-20, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(-3, -4).Range("A1").Select
End Sub
I tried changing all of the "ActiveCell" references to "inputRange", but the macro errors out on the line before the "FALSE" lines begin.
Can someone help me correct this?
I want the user to be able to press the "Clear Form" button on any recipe in a recipe pricing spreadsheet and clear the individual recipe. I recorded the following macro with relative cell references so that I can use one macro for all recipes. The sample spreadsheet only has 2 recipe sections, but the actual spreadsheet where I will be using this has 100.
Sub ClearRecipe()
'
' ClearRecipe Macro
'
'
ActiveCell.Offset(0, 1).Range("A1:C1").Select
Selection.ClearContents
ActiveCell.Offset(3, -1).Range("A1:D16").Select
Selection.ClearContents
ActiveCell.Offset(18, 3).Range("A1:A2").Select
Selection.ClearContents
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.ClearContents
ActiveCell.Offset(-20, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(5, -1).Range("A1").Select
End Sub
This works as long as the user knows to click the Recipe # before clicking the "Clear Form" button.
I want the user to be able to click the "Clear Form" button no matter where the cursor is located, so I added the following code to ask for an input cell, hoping it would then start the relative references later in the macro with the user input. It did not work.
Sub ClearRecipe_inputRange()
'
' ClearRecipe_inputRange Macro
'
'
Dim inputRange As Range
On Error Resume Next
Set inputRange = Application.InputBox("Click Recipe # to delete.", Type:=8)
On Error GoTo 0
If Nothing Is inputRange Then
MsgBox "No Recipe # Chosen."
Else
MsgBox "Recipe " & inputRange.Value & " was chosen."
End If
ActiveCell.Offset(0, 1).Range("A1:C1").Select
Selection.ClearContents
ActiveCell.Offset(3, -1).Range("A1:C16").Select
Selection.ClearContents
ActiveCell.Offset(18, 3).Range("A1:A2").Select
Selection.ClearContents
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.ClearContents
ActiveCell.Offset(-20, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = "FALSE"
ActiveCell.Offset(-3, -4).Range("A1").Select
End Sub
I tried changing all of the "ActiveCell" references to "inputRange", but the macro errors out on the line before the "FALSE" lines begin.
Can someone help me correct this?