Recorded Macro keeps breaking??? need help fixing

scthread

New Member
Joined
Jul 26, 2014
Messages
8
I have a recorded macro that basically takes a selected row, cut's it, then moves it to a different sheet and inserts it at line 2, then re-formats the data to just the values and then returns to the original sheet and deletes the now empty line.

I have recorded this macro several times but when I attempt to use it after attaching to an active x button it breaks!

I get a Run Time Error '1004'
Select method of Range class failed

When I click on Debug it highlight the line of code showing where I select line 2 on the new sheet to insert the cut data.

Here is my code completely un-adulterated from the "recorded" version:


<code>
Private Sub RFQHistory_Click()
'
' RFQHistory - Moves data to RFQ History Tab and freezes time on that tab for a final snapshot, also removes the line from SLA CLOCK completely
'
Selection.Cut
Sheets("RFQ History").Select
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("SLA CLOCK").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub

</code>

How can this be what the wizard "records" yet not work? The only thing I did, was moved it from the Module to the Sheet1 Object.

Any help would be greatly appreciated
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I did a "slight" rewrite of this (removed Private, and changed Tab names to suit) but then had no problems, even added a button.

Wonder if you needed to select the sheet from where you initiated your selection.
 
Upvote 0
Another possible problem not related to your question :
Code:
[COLOR=#333333][FONT=monospace]Sheets("SLA CLOCK").Select[/FONT][/COLOR]
[COLOR=#333333][FONT=monospace]Application.CutCopyMode = False[/FONT][/COLOR]
[COLOR=#333333][FONT=monospace]Selection.Delete Shift:=xlUp[/FONT][/COLOR]

This bit of code deletes whatever is selected on SLA CLOCK.
Unless SLA CLOCK is the starting sheet, the cells selected might not be the ones you want deleted, in which case the cells to be deleted should be specified.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,131
Members
449,206
Latest member
burgsrus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top