Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Adding button in sheet & assigning it to a macro

I am wanting to add a single clickable button inside of a cell on a worksheet
that automatically runs a macro. I have never created a button inside a
sheet and am still new to VBA. What is the best way to go about this?

Here's the Macro

Sub CopyTrackStatsValuesforSorting()
'
'COPIES THE Track Stats WORKSHEET TO A NEW WORKBOOK WHERE IT CAN BE SORTED
'WITHOUT SCREWING UP THE CELL FORMULAS


'MAKES THE Races WORKSHEET ACTIVE
Worksheets("Track Stats").Select

'SELECTS THE APPROPRIATE CELLS TO COPY
Rows("2:65536").Select
Selection.Copy

'ADDS A NEW WORKBOOK WITH NEW SHEET NAME
Workbooks.Add
ActiveSheet.Name = "Sortable Track Stats"

'COPIES ONLY SPECIFIC FORMATS & NUMBERS
With Worksheets("Sortable Track Stats").Range("A2:IV65536")
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlFormats
.PasteSpecial xlPasteColumnWidths
End With

'UNPROTECTS NEW SHEET & DELETES FIRST DROPDOWN ROW
Rows("1:1").Select
ActiveSheet.Unprotect
Selection.delete Shift:=xlUp

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Adding button in sheet & assigning it to a macro

All you have to do is add a macro and then view the code. Then paste your
code in the macro that excel generates

From Worksheet menu
1) View - Toolbars - control toolbar
2) Click on button and then click on worksheet. button will be added.
3) You should now be in Design Mode. the triangle on the toolbar is a
toggle button that puts you either in or out of Design Mode. Sometimes you
need to enter design mode to move a control or modify the control
4) The Property button on the tool bar allows you to change options on the
button like the Caption. You probably wnat to change the name on the Button
to describe what the macro is doing. Press the contol button and then press
properties to see the diferent settings.
5) After you change the caption name then create the macro by right click on
the button and select Veiw Code. A Macro should be place on the VBA Sheet
where the button is located.
6) Put you macro inside the newly created macro.
7) Go back to worksheet and exit Design Mode by click on the Triangle on the
toolbar.
8) Now the button should be operational.

"Brian" wrote:

I am wanting to add a single clickable button inside of a cell on a worksheet
that automatically runs a macro. I have never created a button inside a
sheet and am still new to VBA. What is the best way to go about this?

Here's the Macro

Sub CopyTrackStatsValuesforSorting()
'
'COPIES THE Track Stats WORKSHEET TO A NEW WORKBOOK WHERE IT CAN BE SORTED
'WITHOUT SCREWING UP THE CELL FORMULAS


'MAKES THE Races WORKSHEET ACTIVE
Worksheets("Track Stats").Select

'SELECTS THE APPROPRIATE CELLS TO COPY
Rows("2:65536").Select
Selection.Copy

'ADDS A NEW WORKBOOK WITH NEW SHEET NAME
Workbooks.Add
ActiveSheet.Name = "Sortable Track Stats"

'COPIES ONLY SPECIFIC FORMATS & NUMBERS
With Worksheets("Sortable Track Stats").Range("A2:IV65536")
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlFormats
.PasteSpecial xlPasteColumnWidths
End With

'UNPROTECTS NEW SHEET & DELETES FIRST DROPDOWN ROW
Rows("1:1").Select
ActiveSheet.Unprotect
Selection.delete Shift:=xlUp

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Adding button in sheet & assigning it to a macro

Thanks Joel - that pointed me in the right direction and I decided to use the
Forms control.

"Joel" wrote:

All you have to do is add a macro and then view the code. Then paste your
code in the macro that excel generates

From Worksheet menu
1) View - Toolbars - control toolbar
2) Click on button and then click on worksheet. button will be added.
3) You should now be in Design Mode. the triangle on the toolbar is a
toggle button that puts you either in or out of Design Mode. Sometimes you
need to enter design mode to move a control or modify the control
4) The Property button on the tool bar allows you to change options on the
button like the Caption. You probably wnat to change the name on the Button
to describe what the macro is doing. Press the contol button and then press
properties to see the diferent settings.
5) After you change the caption name then create the macro by right click on
the button and select Veiw Code. A Macro should be place on the VBA Sheet
where the button is located.
6) Put you macro inside the newly created macro.
7) Go back to worksheet and exit Design Mode by click on the Triangle on the
toolbar.
8) Now the button should be operational.

"Brian" wrote:

I am wanting to add a single clickable button inside of a cell on a worksheet
that automatically runs a macro. I have never created a button inside a
sheet and am still new to VBA. What is the best way to go about this?

Here's the Macro

Sub CopyTrackStatsValuesforSorting()
'
'COPIES THE Track Stats WORKSHEET TO A NEW WORKBOOK WHERE IT CAN BE SORTED
'WITHOUT SCREWING UP THE CELL FORMULAS


'MAKES THE Races WORKSHEET ACTIVE
Worksheets("Track Stats").Select

'SELECTS THE APPROPRIATE CELLS TO COPY
Rows("2:65536").Select
Selection.Copy

'ADDS A NEW WORKBOOK WITH NEW SHEET NAME
Workbooks.Add
ActiveSheet.Name = "Sortable Track Stats"

'COPIES ONLY SPECIFIC FORMATS & NUMBERS
With Worksheets("Sortable Track Stats").Range("A2:IV65536")
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlFormats
.PasteSpecial xlPasteColumnWidths
End With

'UNPROTECTS NEW SHEET & DELETES FIRST DROPDOWN ROW
Rows("1:1").Select
ActiveSheet.Unprotect
Selection.delete Shift:=xlUp

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Adding button in sheet & assigning it to a macro

Your other option is to put a custom button in the toolbars and the top of
the worksheet.

"Brian" wrote:

Thanks Joel - that pointed me in the right direction and I decided to use the
Forms control.

"Joel" wrote:

All you have to do is add a macro and then view the code. Then paste your
code in the macro that excel generates

From Worksheet menu
1) View - Toolbars - control toolbar
2) Click on button and then click on worksheet. button will be added.
3) You should now be in Design Mode. the triangle on the toolbar is a
toggle button that puts you either in or out of Design Mode. Sometimes you
need to enter design mode to move a control or modify the control
4) The Property button on the tool bar allows you to change options on the
button like the Caption. You probably wnat to change the name on the Button
to describe what the macro is doing. Press the contol button and then press
properties to see the diferent settings.
5) After you change the caption name then create the macro by right click on
the button and select Veiw Code. A Macro should be place on the VBA Sheet
where the button is located.
6) Put you macro inside the newly created macro.
7) Go back to worksheet and exit Design Mode by click on the Triangle on the
toolbar.
8) Now the button should be operational.

"Brian" wrote:

I am wanting to add a single clickable button inside of a cell on a worksheet
that automatically runs a macro. I have never created a button inside a
sheet and am still new to VBA. What is the best way to go about this?

Here's the Macro

Sub CopyTrackStatsValuesforSorting()
'
'COPIES THE Track Stats WORKSHEET TO A NEW WORKBOOK WHERE IT CAN BE SORTED
'WITHOUT SCREWING UP THE CELL FORMULAS


'MAKES THE Races WORKSHEET ACTIVE
Worksheets("Track Stats").Select

'SELECTS THE APPROPRIATE CELLS TO COPY
Rows("2:65536").Select
Selection.Copy

'ADDS A NEW WORKBOOK WITH NEW SHEET NAME
Workbooks.Add
ActiveSheet.Name = "Sortable Track Stats"

'COPIES ONLY SPECIFIC FORMATS & NUMBERS
With Worksheets("Sortable Track Stats").Range("A2:IV65536")
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlFormats
.PasteSpecial xlPasteColumnWidths
End With

'UNPROTECTS NEW SHEET & DELETES FIRST DROPDOWN ROW
Rows("1:1").Select
ActiveSheet.Unprotect
Selection.delete Shift:=xlUp

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
assigning a macro to a button Darby Excel Discussion (Misc queries) 2 February 10th 06 05:05 PM
Assigning macro to button d Excel Discussion (Misc queries) 0 August 22nd 05 01:40 PM
Assigning a macro to a button Junkyard Engineer Excel Programming 3 June 9th 05 02:00 PM
Assigning a macro to a "button" Yvon Excel Discussion (Misc queries) 6 February 8th 05 10:58 PM
Adding module - assigning macro to button a Excel Programming 1 September 2nd 04 01:55 AM


All times are GMT +1. The time now is 10:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"