Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Assign code to button
H
I found the following code whilst surfing the net and thought it would be very useful to me as i am currently compiling a list of some 24 columns in Excel. It does do exactly what it is meant to do i.e. upon right clicking within a row it shows me the contents of all columns within that row, which is great. However, there are times when i really could do with being able to turn this function off so that i can use the shortcut menus Could anybody tell me a step by step way of assigning this code to a button so that i can turn this feature on and off as and when i require it? Just so you know, i am totally unfamiliar with VBA so please be gentle with me Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean Dim intCounter As Intege Dim txt As Strin If Target.Column 24 Then Exit Su Cancel = Tru For intCounter = 1 To 2 txt = txt & Cells(Target.Row, intCounter) & vbL Next intCounte MsgBox tx End Su Many thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Assign code to button
Hi
Insert a button from the Control toolbox and make its code (rightclick it view code) look like this: Private Sub CommandButton1_Click() Dim intCounter As Integer Dim txt As String If ActiveCell.Column 24 Then Exit Sub For intCounter = 1 To 24 txt = txt & Cells(ActiveCell.Row, intCounter) & vbLf Next intCounter MsgBox txt End Sub -- HTH. Best wishes Harald Followup to newsgroup only please. "Nic" wrote in message ... Hi I found the following code whilst surfing the net and thought it would be very useful to me as i am currently compiling a list of some 24 columns in Excel. It does do exactly what it is meant to do i.e. upon right clicking within a row it shows me the contents of all columns within that row, which is great. However, there are times when i really could do with being able to turn this function off so that i can use the shortcut menus. Could anybody tell me a step by step way of assigning this code to a button so that i can turn this feature on and off as and when i require it? Just so you know, i am totally unfamiliar with VBA so please be gentle with me. Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) Dim intCounter As Integer Dim txt As String If Target.Column 24 Then Exit Sub Cancel = True For intCounter = 1 To 24 txt = txt & Cells(Target.Row, intCounter) & vbLf Next intCounter MsgBox txt End Sub Many thanks |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Assign code to button
Hi Harol
Thank you so much for that, it has worked a treat. You would not believe the hours i have spent trying to work out how to do that!!! Many, Many thanks again Nic |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Assign code to button
Glad it worked Nic. Thank you for the feedback.
Best wishes Harald Followup to newsgroup only please "Nic" skrev i melding ... Hi Harold Thank you so much for that, it has worked a treat. You would not believe the hours i have spent trying to work out how to do that!!! Many, Many thanks again. Nic |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Assign a macro to a button | Excel Discussion (Misc queries) | |||
assign button for color | Excel Worksheet Functions | |||
How can I assign a symbol to a button (like the $ button) | Excel Discussion (Misc queries) | |||
How do I Assign Macro to a button? | Charts and Charting in Excel | |||
Assign button to run macro | Excel Programming |