1

I wrote a script to ask for user input. I know how to write the script to enter it into one cell or enter it into every empty cell at the end of the row. What I don't know is how to write it so that the user input value is inputted in one cell on two separate sheets. Can someone help me re-write this code to do that?

Sub AddText()
Dim myRange As String
myRange = Application.inputbox("Enter Item Number", "1")
Range("S1").Value = myRange
End Sub

2 Answers 2

1

Qualify the range with the worksheet object associated with it (this is also best practice, no matter what you're doing). I also changed the variable name to make more sense because its best practice to have meaningful and clear variable names (and a Range usually refers to one more spreadsheet cells, not a string value.

Sub AddText()

    Dim sInput as String
    sInput = Application.inputbox("Enter Item Number", "1")

    Worksheets("Sheet1").Range("S1").Value = sInput
    Worksheets("Sheet2").Range("S1").Value = sInput

End Sub
Sign up to request clarification or add additional context in comments.

Comments

1
Sheets("Sheet1").Range("S1").Value = myRange
Sheets("Sheet2").Range("S1").Value = myRange

1 Comment

So simple... Thanks ChrisM!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.