pastespecial
Posted by A.y. on September 27, 2001 4:49 AM
I'm having problems with a line of a certain code I've written in vba for excel. When ever I run the program I get a runtime error '1004' "PasteSpecial method range class failed. When I choose to debug the program it hilights the line with "selection.paste". Whats most interesting is that when ever I choose to end the run and re-run the program right after it works fine. By the way I'm using excel 97. Here is a cutout of the code if it helps:
Private Sub CommandButton1_Click()
Dim DEPT, CHARNUM, SEARC As Variant
Dim I, J, BAL, BALL, K As Long
Application.ScreenUpdating = False
Sheets("Sheet1").Select
If Range("O1").Value = "" Then
MsgBox ("YOU ARE NOT LOGGED IN")
Unload UserForm8
Exit Sub
ElseIf Range("P1").Value = 3 Then
MsgBox ("YOU ARE NOT AUTHORIZED FOR THIS PROCEDURE")
Unload UserForm8
Exit Sub
End If
I = 3
J = 2
BALL = 0
SEARC = TextBox1.Value
Do
Sheets("SHEET2").Select
Cells(I, 1).Select
With ActiveCell
Set C = .Find(What:=SEARC)
If Not C Is Nothing Then
BAL = Cells(I, 7).Value - TextBox4.Value
DEPT = TextBox2.Value
CHARNUM = TextBox3.Value
ActiveSheet.Rows(I).Copy
Sheets("TRANSACTION").Select
ActiveSheet.Unprotect Password:="AYODELE"
Do
J = J + 1
Cells(J, 1).Select
If Val(ActiveCell.Value) = SEARC Then
BALL = Cells(J, 7).Value
BAL = BALL - TextBox4.Value
End If
If ActiveCell.Value = "" Then
Selection.PasteSpecial
Application.CutCopyMode = False
Cells(J, 7) = BAL
Cells(J, 12) = DEPT
Cells(J, 13) = CHARNUM
Cells(J, 14) = Sheets("Sheet1").Range("O1").Value
Cells(J, 15) = Date
Cells(J, 18).ClearContents
Cells(J, 19).ClearContents
Sheets("Sheet2").Select
Cells(I, 7) = BAL
Sheets("Sheet4").Visible = True
Sheets("Sheet4").Select
ActiveSheet.Unprotect Password:="AYODELE"
K = 2
Do
If Val(Cells(K, 1).Value) = SEARC Then
Cells(K, 7) = BAL
ActiveSheet.Protect Password:="AYODELE"
Sheets("Sheet4").Visible = False
Sheets("TRANSACTION").Select
Exit Do
End If
K = K + 1
Loop Until Cells(K, 1).Value = ""
GoTo Line2
End If
Loop Until Cells(J, 1).Value = ""
End If
End With
I = I + 1
Loop Until Sheets("SHEET2").Cells(I, 1).Value = ""
Line2:
Cells(J, 1).Select
Sheets("TRANSACTION").Protect Password:="AYODELE"
Application.ScreenUpdating = True
Unload UserForm8
End Sub
Thankyou for your help.
A.y.