Hello Excel Forum,
On one worksheet I have a range of column headers. Underneath this range of column headers I'd like to copy and paste values that are calculated in another sheet. In the first step I set a variable equal to the length of the column headings, but I'm getting the run-time error 1004: method range of object worksheet failed. I'm thinking this may be an easy syntax problem but I couldn't find any solutions in the forum or through google.
This is my command button code:
Private Sub CommandButton1_Click()
Dim lngCounter As Long
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws3 As Worksheet
Set ws1 = Sheets("Catch for Port Calc")
Set ws2 = Sheets("2 - Dashboard")
Set ws3 = Sheets("18 - Catch and Days at Sea")
For lngCounter = 4 To ws1.Range(6, Columns.Count).End(xlToLeft).Column
If ws1.Cells(6, lngCounter).Value <> "" Then
ws2.Range("C3").Value = ws1.Cells(6, lngCounter).Value
ws1.Cells(7, lngCounter).Resize(150, 1).Value = ws3.Range("C6").Resize(150, 1).Value
End If
Next lngCounter
Set ws3 = Nothing
Set ws2 = Nothing
Set ws1 = Nothing
End Sub
My workbook is quite large and still in development so I have copied and pasted the three relevant worksheets to a new document:Modified Workbook for Excelforum.xlsm Let me know if any more information is required.
Many thanks in advance!
Griffin
Bookmarks