'VBA - worksheet object is hidden

I have a very simple yet seemingly unsolvable problem: I would like to copy a range of data from a worksheet to another.

This is what I made up:

Sub CopyProjectData
Worksheets("Projects").Range(Cells(1001, 1), cells(1002,1).Value = Worksheets("Road").Range(Cells(4, 1), Cells(5, 1)).Value
End Sub

(I used Cells(...) in range, because in the future I'd like to use dynamic ranges)

However -no matter how I try to change the syntax- the damn thing keeps telling me:

'Cannot jump to 'Worksheets' because it is hidden'

What do I do wrong?



Solution 1:[1]

What if you tried something like this.

Sub CopyRange()
    Sheets("Projects").Select
    Range(Range("A13").Value + ":" + Range("B13").Value).Select
    Selection.Copy
    Sheets("Road").Select
    Range("B3").Select
    ActiveSheet.Paste
End Sub

The value of A13 contains the location of the upper left cell of the range.

The value of B13 contains the location of the lower right cell of the range.

Range(B3) is the upper left corner of the destination for the copied data.

Solution 2:[2]

Here's the MSDN page for that error. I can't think why you're getting it.

I do notice that you're missing a closing parenthesis. And until I modified your code I got an unspecified Application error.

Also, your code isn't fully qualified, e.g., it doesn't specify which Workbook the Worksheets are in or which Sheet the Cells are in. So I took the liberty of fully fleshing it out. If nothing else it should be easier to debug:

Sub CopyProjectData()
Dim cellFrom As Excel.Range
Dim cellTo As Excel.Range

With ThisWorkbook.Worksheets("Road")
    Set cellFrom = .Range(.Cells(4, 1), .Cells(5, 1))
End With
With ThisWorkbook.Worksheets("Projects")
    Set cellTo = .Range(.Cells(1001, 1), .Cells(1002, 1))
End With
cellTo.Value = cellFrom.Value
End Sub

Solution 3:[3]

Sometimes It has to do with having your worksheet protected. Check to see if it is protected under the Review Tab. If it says Unprotect Sheet under the Review Label then you may have to add a command in your code to unprotect and then protect at the end again.

Ie.

ActiveSheet.Unprotect

INSERT CODE HERE FOR YOUR WORKSHEET

Active Sheet.Protect  

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jhadley
Solution 2 Doug Glancy
Solution 3 Robert