LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
dk dk is offline
external usenet poster
 
Posts: 129
Default error; " 'Range' of object '_Worksheet' failed"?

Sheet1 has a list of records and additional "fields" that are common to all
records.
Sheet2 has a single row of formulas "ExpRow" that needs to be copied down
for the number of records on Sheet1.
The following code is in a general module and works well *Only* when Sheet2
is active.
If the active sheet is not Sheet2 I get the error; " 'Range' of object
'_Worksheet' failed".
This error happens at each statement that interacts with Sheet2 begining
with ExpRows = Sheet2.Range(Cells(2, 1), Cells(4000, c)).Address
How can I rephase the statements to allow the the code to run regardless of
which sheet is active?
Also, I may move this code to Sheet1 to activate it with a button. Will this
affect the syntax?
Thank you.

Sub Build_Export()
Dim ExpRows As String, r As Integer, c As Integer, LastMtrRow As Long,
Msg As String
r = Range("MtrCounter").Value
c = Range("ExpRow").Columns.Count
LastMtrRow = Sheet1.Range("A65536").End(xlUp).Row -
Range("MtrHeader").Row
Msg = "Check for blank rows in the Input list."
ExpRows = Sheet2.Range(Cells(2, 1), Cells(4000, c)).Address

Range(ExpRows).Clear
If LastMtrRow < 1 Or LastMtrRow < Range("MtrCounter").Value _
Then
Info = MsgBox(Msg, vbInformation, "Missing Information")
Exit Sub
Else
Sheet2.Range(Cells(2, 1), Cells(r, c)) = Range("ExpRow").Formula
End If

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Help - Method "Range" of object "_Worksheet" failed. Alan Smith Excel Programming 3 March 15th 07 06:55 PM
Error in Macro: "Method 'Paste' of object '_Worksheet' failed" blork Excel Programming 7 March 5th 06 05:48 PM
What is Error "Method "Paste" of object "_Worksheet" failed? vat Excel Programming 7 February 17th 06 08:05 PM
"method 'Copy' of object '_Worksheet' failed" Terry Holland Excel Programming 1 July 8th 05 04:25 PM
METHOD "SELECT" OF OBJECT '_WORKSHEET' FAILED when opening a file Mat Excel Programming 0 July 8th 04 05:13 PM


All times are GMT +1. The time now is 08:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"