Consulting

Results 1 to 4 of 4

Thread: Solved: Setting the value in another worksheet

  1. #1

    Angry Solved: Setting the value in another worksheet

    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.

    What'd I do wrong?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    There is absolutely nothing wrong with that code (apart from putting 3 in quotes), so what error did you get?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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.

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    [VBA] '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[/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •