LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Run Time Error 1004

Hi,

I am trying to run the following code but when i do it it falls over after
after about 200 lines with the following error message:-

Run Time Error 1004 Pastespecial Method of range class failed:-

Can someone please look at the code to find out why it's falling over on
this message?????? Thanks

Private Sub CommandButton1_Click()

'Works out how many setups we have on the PPM sample and calculate there value

Dim Message As String
Dim Myquestion As String

Application.ScreenUpdating = False


'Alerts the user how long it could take to run the calculations

Myquestion = "Are you sure you want to run calculation for " _
& Range("b1").Value - 11 & " accounts, this could take " _
& Round((Range("b1").Value - 11) / 2.4 / 60, 2) _
& " Minutes"

Message = MsgBox(Myquestion, vbQuestion + vbYesNo, "SetupCalculations")

If Message = vbNo Then

MsgBox "NO Calculations Done!!", vbOKOnly, "SetupCalculations"

Else

counter = 11
mynum = Range("b1")

Do While counter <= mynum

'The below few lines copy the fields needed to work out the asset setup value



Range("B10:ann10").Select

Selection.Copy
Range("B" & counter).Select

Range("B" & counter & ":ANN" & counter).Select

Selection.PasteSpecial xlPasteAll

Application.CutCopyMode = False


'The below few lines work out the asset value for setup assets

Application.CutCopyMode = True

Range("L60014:ANP60014").Select

Selection.Copy
Range("L" & counter + 60004).Select

Range("L" & counter + 60004 & ":ANP" & counter + 60004).Select

Selection.PasteSpecial xlPasteAll

Application.CutCopyMode = False

'The below few line will paste special values into the calculated setups
assets after they have been calculated. Doing this will
'save on file size and make the calcualtions run quicker.

Application.CutCopyMode = True

Range("B" & counter & ":ANN" & counter).Select

Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues

Application.CutCopyMode = False

Application.CutCopyMode = True

Range("L" & counter + 60004 & ":ANP" & counter + 60004).Select

Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues

Application.CutCopyMode = False

'The below line stop the code from copy mode and put the cursor back to cell
B9

mynum = mynum
counter = counter + 1

Loop

Range("b9").Select

Application.ScreenUpdating = True

Range("r3").Value = WorksheetFunction.Sum(Range("ANP60014:ANP1048576") ) /
WorksheetFunction.Sum(Range("C60014:C1048576"))

MsgBox "Your calculations are complete", vbOKOnly, "SetupCalculations"

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
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
Run time error 1004 Object defined error [email protected] Excel Programming 1 May 15th 07 03:31 AM
Run Time Error 1004: Application or Object Defined Error BEEJAY Excel Programming 4 October 18th 06 04:19 PM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 12:38 PM.

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"