# Excel VB script (Macro vs Command button)

**URL:** <https://forum.kirupa.com/t/excel-vb-script-macro-vs-command-button/210404>\
**Category:** web dev\
**Created:** [December 18, 2006, 3:29pm UTC](https://forum.kirupa.com/t/excel-vb-script-macro-vs-command-button/210404 "2006-12-18T15:29:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Vulcan](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/the_vulcan/32/145_2.png) [@The\_Vulcan](https://forum.kirupa.com/u/The_Vulcan)\
**Post date:** [December 18, 2006, 3:29pm UTC](https://forum.kirupa.com/t/excel-vb-script-macro-vs-command-button/210404/1 "2006-12-18T15:29:32Z")

</div>

[COLOR=Red]\*\*\*\*\* SOLVED \*\*\*\*\*[/COLOR]

I am trying to set up a number of buttons in Excel.  
I have been recording Macro’s to help get the VB script.

However I now have code that works when run as a Macro but not when run as a command button.

\*\* Any ideas ?\*\*

> Private Sub CommandButton1\_Click()

Range(“C6:F6”).Select  
Selection.Copy  
Sheets(“Sheet2”).Select  
[COLOR=Magenta]\*\* Range(“C6”).Select \*\*[/COLOR]  
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks \_  
:=False, Transpose:=False  
Sheets(“Sheet1”).Select  
Application.CutCopyMode = False  
Selection.ClearContents  
Range(“C4”).Select  
End Sub  
\*\*FAILS [COLOR=Magenta]on pink section[/COLOR]

\*\*

> Sub Macro4()

```
Range("C8:F8").Select
Selection.Copy
Sheets("Sheet2").Select
Range("C4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Sheets("Sheet1").Select
Application.CutCopyMode = False
Selection.ClearContents
Range("C4").Select

```

End Sub

\*\*WORKS

Its the exact same code…  
Creating macros and then attaching code has worked for others…  
\*\*
