Code works, but won't start when I attach it to a button

Calinora

New Member
Joined
Oct 9, 2018
Messages
13
I hope you can help me yet again.

I have a code that works, however when I attach it to a button it doesn't run.

I hope you can help me fix it.

Code:
Sub CopyFormatting()


    Dim lRow As Long


     lRow = ActiveSheet.Cells.Find("*", LookIn:=xlValues, Searchorder:=xlByRows, Searchdirection:=xlPrevious).Row + 1
    
    Range("B19:Z19").Copy
    ActiveSheet.Cells(lRow, 2).PasteSpecial xlPasteAll


    Application.CutCopyMode = xlCopy


End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
A few questions
1) Where is the code located?
2) What sheet is the button located on?
3) What sheet are you trying to copy from?
4) What sheet are you trying to paste on?
 
Upvote 0
I've got it to work again, thanks to your questions.
Macros are enabled yes.

It was in a module, but somehow it got overruled by a different module i had. After I deleted that it worked perfectly.
Lets call it sheet 2 where the button was located.
Copying from sheet 2
Pasting to sheet 2

Thanks!
 
Upvote 0
Glad you got it working & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,225,754
Messages
6,186,825
Members
453,377
Latest member
JoyousOne

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