Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default 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
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
Assign a macro to a button totofab Excel Discussion (Misc queries) 4 December 13th 07 06:16 PM
assign button for color bk Excel Worksheet Functions 9 April 8th 07 04:04 PM
How can I assign a symbol to a button (like the $ button) NickW Excel Discussion (Misc queries) 2 September 6th 05 02:45 PM
How do I Assign Macro to a button? BellExcel Charts and Charting in Excel 4 May 20th 05 07:21 PM
Assign button to run macro jamie85[_5_] Excel Programming 8 February 3rd 04 01:44 PM


All times are GMT +1. The time now is 03:21 AM.

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

About Us

"It's about Microsoft Excel"