Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc,microsoft.public.excel.programming
teepee
 
Posts: n/a
Default Userform button setting variable from formula

I have a userform that contains windows media player. I want to set
CommandButton4 to take the value of the formula in cell A2 of the active
sheet and set it as the value of variable named 'inset'. I'm finding the VBA
code on this much harder to write than I thought it would be. Any ideas
please, anyone?


  #2   Report Post  
Posted to microsoft.public.excel.misc
ShaunM
 
Posts: n/a
Default Userform button setting variable from formula


Hi Teepee

I am a bit confused by your request but I think that it as simple as:

Private Sub CommandButton4_Click()
inset = Range("A2").Value
MsgBox ("The value of cell A2 is: " & inset)
End Sub

Regards
Shaun


--
ShaunM
------------------------------------------------------------------------
ShaunM's Profile: http://www.excelforum.com/member.php...o&userid=18610
View this thread: http://www.excelforum.com/showthread...hreadid=497673

  #3   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc,microsoft.public.excel.programming
teepee
 
Posts: n/a
Default Userform button setting variable from formula


"ShaunM" wrote

I am a bit confused by your request but I think that it as simple as:

Private Sub CommandButton4_Click()
inset = Range("A2").Value
MsgBox ("The value of cell A2 is: " & inset)
End Sub


Thanks Shaun, that's kind of you to respond. I think the problem with your
suggestion might be that the variable is only then available within the
userform itself whereas I need to refer to the variable within other macros.
Do I not need another approach if the variable is to be generally available
elsewhere in the spreadsheet?


  #4   Report Post  
Member
 
Location: London
Posts: 78
Default

All you need to do is use the example above, except you need to add a Module to the project and declare the variable as public, like so:

Public inset As Integer

To avoid doubt it would probably be best to refer to the variable in code as
Module1.inset (replace 'Module1' with the module name if you change it).

Regards,
BizMark
  #5   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc,microsoft.public.excel.programming
teepee
 
Posts: n/a
Default Userform button setting variable from formula


"BizMark" wrote

All you need to do is use the example above, except you need to add a
Module to the project and declare the variable as public, like so:

Public inset As Integer


Worked a treat. Many thanks to you both

tp




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
Userform button setting variable from formula teepee Excel Discussion (Misc queries) 0 January 3rd 06 08:26 PM
Match then lookup Tenacity Excel Worksheet Functions 9 December 3rd 05 05:30 AM
Dragging a Formula & Basic Setting Changes chande00 Excel Discussion (Misc queries) 4 June 2nd 05 09:43 PM
Use the X button on a userform Greg B Excel Discussion (Misc queries) 3 May 16th 05 09:19 AM
Formula for button name Adam Excel Worksheet Functions 1 April 22nd 05 05:10 PM


All times are GMT +1. The time now is 07:23 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"