Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Using pop up boxes to supply a variable within a macro


Hi

I have a piece of code as part of a macro which subtracts 1 from a value
in cell D2

ActiveCell.FormulaR1C1 = "=RC[1]-1"

Sometimes , I need to vary this number. Rather than open the macro and
change the code each time , is it possible to program a popup to request
the value of the variable , and once executed proceed with the rest of
the macro?

Any help appreciated.



Best Wishes
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 59
Default Using pop up boxes to supply a variable within a macro

On 27 Jan, 05:16, Colin Hayes wrote:
Hi

I have a piece of code as part of a macro which subtracts 1 from a value
in cell D2

ActiveCell.FormulaR1C1 = "=RC[1]-1"

Sometimes , I need to vary this number. Rather than open the macro and
change the code each time , is it possible to program a popup to request
the value of the variable , and once executed proceed with the rest of
the macro?

Any help appreciated.



This might work. Put it at the top of your code:-

Dim intNumber as integer
intNumber = inputbox("Please enter the number you wish to subtract
by","Enter number")

This will then store the number you wish to subtract by into the
variable intNumber. The next bit of your code would then look like
this:-

ActiveCell.FormulaR1C1="=RC[1]-"&intNumber

And that should pretty much do the trick. Hope this helps.

Regards,
Matt Richardson
http://teachr.blogspot.com
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 59
Default Using pop up boxes to supply a variable within a macro

On 27 Jan, 11:16, Matt Richardson wrote:
On 27 Jan, 05:16, Colin Hayes wrote:

Hi


I have a piece of code as part of a macro which subtracts 1 from a value
in cell D2


ActiveCell.FormulaR1C1 = "=RC[1]-1"


Sometimes , I need to vary this number. Rather than open the macro and
change the code each time , is it possible to program a popup to request
the value of the variable , and once executed proceed with the rest of
the macro?


Any help appreciated.


This might work. Put it at the top of your code:-

Dim intNumber as integer
intNumber = inputbox("Please enter the number you wish to subtract
by","Enter number")

This will then store the number you wish to subtract by into the
variable intNumber. The next bit of your code would then look like
this:-

ActiveCell.FormulaR1C1="=RC[1]-"&intNumber

And that should pretty much do the trick. Hope this helps.

Regards,
Matt Richardsonhttp://teachr.blogspot.com


You might want to change the 'Dim intnumber...' bit to this actually:-

Dim intNumber as double

The prior version will only work with integers and therefore would
only work with whole numbers. Changing the type of variable means
that you can subtract decimals as well.

Regards,
Matt Richardson
http://teachr.blogspot.com
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Using pop up boxes to supply a variable within a macro



HI

OK thanks for your help with that - worked perfectly , first time.

Much appreciated.

I made a small variation , so that positive numbers , as well as
negative , could be entered :

ActiveCell.FormulaR1C1="=RC[1]+"&intNumber


Thanks again.

Best wishes.




In article
,
Matt Richardson writes
On 27 Jan, 11:16, Matt Richardson wrote:
On 27 Jan, 05:16, Colin Hayes wrote:

Hi


I have a piece of code as part of a macro which subtracts 1 from a value
in cell D2


ActiveCell.FormulaR1C1 = "=RC[1]-1"


Sometimes , I need to vary this number. Rather than open the macro and
change the code each time , is it possible to program a popup to request
the value of the variable , and once executed proceed with the rest of
the macro?


Any help appreciated.


This might work. Put it at the top of your code:-

Dim intNumber as integer
intNumber = inputbox("Please enter the number you wish to subtract
by","Enter number")

This will then store the number you wish to subtract by into the
variable intNumber. The next bit of your code would then look like
this:-

ActiveCell.FormulaR1C1="=RC[1]-"&intNumber

And that should pretty much do the trick. Hope this helps.

Regards,
Matt Richardsonhttp://teachr.blogspot.com


You might want to change the 'Dim intnumber...' bit to this actually:-

Dim intNumber as double

The prior version will only work with integers and therefore would
only work with whole numbers. Changing the type of variable means
that you can subtract decimals as well.

Regards,
Matt Richardson
http://teachr.blogspot.com


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,073
Default Using pop up boxes to supply a variable within a macro

On Jan 27, 4:16 pm, Colin Hayes wrote:
Hi

I have a piece of code as part of a macro which subtracts 1 from a value
in cell D2

ActiveCell.FormulaR1C1 = "=RC[1]-1"

Sometimes , I need to vary this number. Rather than open the macro and
change the code each time , is it possible to program a popup to request
the value of the variable , and once executed proceed with the rest of
the macro?

Any help appreciated.

Best Wishes


Maybe Application.InputBox. Something like...

Dim vaNumber
vaNumber = Application.InputBox( _
Prompt:="Enter the number to subtract.", _
Title:="Get Number to Subtract.", _
Default:=1, _
Type:=1)
If vaNumber = False Then
Exit Sub
End If
ActiveCell.FormulaR1C1 = "=RC[1]-" & vaNumber

Although you might not want the Exit Sub part.
vaNumber equals False if the user clicks the Cancel Button.

Ken Johnson


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
macro boxes: toggle on/off Peter Excel Discussion (Misc queries) 1 October 5th 07 09:34 AM
Macro Boxes Peter Excel Discussion (Misc queries) 4 October 5th 07 12:34 AM
Macro Boxes Peter Excel Discussion (Misc queries) 0 October 4th 07 06:06 PM
Entering Variable Text in Text Boxes...... Steve Jones Excel Discussion (Misc queries) 3 June 14th 07 02:34 PM
Macro that can run combo boxes simonsmith Excel Discussion (Misc queries) 0 June 5th 06 05:00 PM


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