Set value of another worksheets cell range

rharri1972

Board Regular
Joined
Nov 12, 2021
Messages
132
Office Version
  1. 2019
Platform
  1. Windows
Good Saturday morning everyone!!

What I want to do if someone doesn't mind helping me is....
I have a macro that will check to make sure ALL cells in a range are empty on sheet ("paste MRP data here"). I have a user form that is triggered when criteria is met. At this point I am on "Sheet1". When i hit the "OK" button on the userform I want to set the value of A1 on sheet ("paste MRP data here") to "Paste Data Here"

I am trying with :
sub setvalue()
application.screenupdating = false
worksheets("paste MRP data here").select
activesheet.range("A1").value = "Paste Data Here"
worksheets("Sheet1").activate
application.screenupdating = true
end sub

I keep getting a subscript out of range error 9

as you can probably see i am new to this and trying to wrap my head around it as well.
any help is greatly appreciated!!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
The macro you presented here works fine on its own. I suspect that the user form/empty range macro is causing the problem. Maybe you can share that macro.
 
Upvote 0
The fact that your code is all in lower case tells me that you've typed it here and not posted your actual code.

Although it could be done much simpler, there is no reason for it to give you runtime error 9 other than the possibility that you have misspelled one of the worksheet names.

Before you do much more, I suggest that you take steps to un-learn the use of Select, it is a command that is never needed and only clutters your code.
VBA Code:
Sub setvalue()
Worksheets("paste MRP data here").Range("A1").Value = "Paste Data Here"
End Sub
 
Upvote 0
Solution
The fact that your code is all in lower case tells me that you've typed it here and not posted your actual code.

Although it could be done much simpler, there is no reason for it to give you runtime error 9 other than the possibility that you have misspelled one of the worksheet names.

Before you do much more, I suggest that you take steps to un-learn the use of Select, it is a command that is never needed and only clutters your code.
VBA Code:
Sub setvalue()
Worksheets("paste MRP data here").Range("A1").Value = "Paste Data Here"
End Sub
thank you for that tip Jason!! Still new so nothing is "stuck" at this moment. LOL
 
Upvote 0
The fact that your code is all in lower case tells me that you've typed it here and not posted your actual code.

Although it could be done much simpler, there is no reason for it to give you runtime error 9 other than the possibility that you have misspelled one of the worksheet names.

Before you do much more, I suggest that you take steps to un-learn the use of Select, it is a command that is never needed and only clutters your code.
VBA Code:
Sub setvalue()
Worksheets("paste MRP data here").Range("A1").Value = "Paste Data Here"
End Sub
Jason, would it have anything to do with the fact this code is in the "command button" of the userform?
 
Upvote 0
The fact that your code is all in lower case tells me that you've typed it here and not posted your actual code.

Although it could be done much simpler, there is no reason for it to give you runtime error 9 other than the possibility that you have misspelled one of the worksheet names.

Before you do much more, I suggest that you take steps to un-learn the use of Select, it is a command that is never needed and only clutters your code.
VBA Code:
Sub setvalue()
Worksheets("paste MRP data here").Range("A1").Value = "Paste Data Here"
End Sub
This is copied straight from my vba editor...
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Worksheets("paste MRP data here").Range("A1").Value = "Paste Data Here"
Worksheets("Sheet1").Activate
Application.ScreenUpdating = True
End Sub
 
Upvote 0
The fact that your code is all in lower case tells me that you've typed it here and not posted your actual code.

Although it could be done much simpler, there is no reason for it to give you runtime error 9 other than the possibility that you have misspelled one of the worksheet names.

Before you do much more, I suggest that you take steps to un-learn the use of Select, it is a command that is never needed and only clutters your code.
VBA Code:
Sub setvalue()
Worksheets("paste MRP data here").Range("A1").Value = "Paste Data Here"
End Sub
thank you Jason...it is working. I just breathed a little...took my time...retyped it and it works. Thanks for your guidance!!
 
Upvote 0
Did you try it with the code from my post? That will do the same as yours but skips out all of the unnecessary steps.
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

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