Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
When I open the workbook the macro runs fine, the next time I run the macro
it fails with "'Runtime error 1004. Paste method of worksheet class failed." I have to manually delete the data from sheet "Print Data", save the excel file and then I can run the macro. I should be able to run this repeatedly. Open Userform and run, open userform and run, etc... '====== Private Sub CommandButton1_Click() If UserPart.Value = "" Then MsgBox "You must enter a Value in " & """Part Number""" & " text box!" End If If IsDate(UserDate.Value) = False Then MsgBox "You must enter a valid date in " & """Job Due By""" & " text box in a Date format (mm/dd/yy)!" End If With Sheets("Part Number") Sh1LastRow = .Cells(Rows.Count, "A").End(xlUp).Row Set Sh1Range = .Range("A2:A" & Sh1LastRow) End With 'MsgBox Sh1LastRow 'for testing For Each Sh1Cell In Sh1Range If Sh1Cell.Value = sUserPart Then x1 = Replace(Sh1Cell.Address, "$", "") x2 = Replace(x1, "A", "") sRowData = x1 & ":H" & x2 'MsgBox sRowData 'for testing Range(sRowData).Select Selection.Copy Sheets("Print Data").Select ActiveSheet.Unprotect "2000" Range("A2").Select ActiveSheet.Paste 'Paste method of worksheet class failed (1004) on second pass? Columns("A:H").Select Selection.Columns.AutoFit Range("A2").Select ActiveSheet.Protect "2000" End If Next Sh1Cell End Sub '====== -- Regards VBA.Noob.Confused XP Pro Office 2007 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro Error 1004 | Excel Discussion (Misc queries) | |||
Formula in macro causes macro to fail | Excel Programming | |||
Excel 2000 = upgraded to 2003 and macro to change font color fail | Excel Programming | |||
A macro that copies and pastes autofiltered cells will fail. | Excel Programming | |||
add-in macro strange errors--method sheets of object workbook fail | Excel Programming |