PDA

View Full Version : Solved: Setting the value in another worksheet



sparafucile1
10-27-2008, 11:56 AM
This is prob a super begginer question, but how do I set the value of a cell in another sheet. Lets say I'm in Sheet1 and I want to set a cell in Sheet3 to the value 3. This is what I tried with no luck:


ThisWorkbook.Sheets("Sheet3").Cells(2, 2).Value = "3"

I get a runtime error and no help with what I did wrong. :banghead:

What'd I do wrong?

Bob Phillips
10-27-2008, 12:01 PM
There is absolutely nothing wrong with that code (apart from putting 3 in quotes), so what error did you get?

sparafucile1
10-27-2008, 12:18 PM
Ooops! I see the problem now. I was getting a run-timer error 1004. But if I'd of opened my eyes before assuming I had coded it wrong, I would have seen that sheet3 was protected!! Duh

So all I need to do is remove the proctection which I am doing elsewhere in VBA code.

Sorry to bother you guys.

GTO
10-27-2008, 12:56 PM
'You can also leave the protection on, by setting the UserInteraceOnly arg.
With ThisWorkbook.Worksheets("Sheet3")
.Protect Password:="If you have it passworded...", _
DrawingObjects:=True, Contents:=True, _
Scenarios:=True, UserInterfaceOnly:=True
.Cells(2, 2).Value = 3
End With