Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default How to define variable

Hi,

I am working on project, and wanted to define a list of variables which
should be called by the macro. Is it possible to define the all
variables in one sheet, say Input, and when macro execute it takes the
necessary values from this sheet. The idea is when we use this Excel
File for other project, I just need to change the variables on this
Input sheet...and the macros remain still valid. Till I used to change
these variables in the macro before running them. Any thoughts how to
do it and how to call these values in Macro.

Many thanks...any help highly appreciated!!!

Regards,
Kishore

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default How to define variable

The macro can obtain the values of the cells in the worksheet and assign them
to the variables in the macro.

In the example below, a equals to the value of cell A1 in sheet "Input". And
b equals to the value of cell A2. The macro then add up the two values and
display it in a messagebox.

Sub example()
Dim a
Dim b
With Worksheets("Input")
a = .Range("A1").Value
b = .Range("A2").Value
End With
MsgBox a + b
End Sub

Regards,
Edwin Tam

http://www.vonixx.com



"kishore" wrote:

Hi,

I am working on project, and wanted to define a list of variables which
should be called by the macro. Is it possible to define the all
variables in one sheet, say Input, and when macro execute it takes the
necessary values from this sheet. The idea is when we use this Excel
File for other project, I just need to change the variables on this
Input sheet...and the macros remain still valid. Till I used to change
these variables in the macro before running them. Any thoughts how to
do it and how to call these values in Macro.

Many thanks...any help highly appreciated!!!

Regards,
Kishore


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default How to define variable

call a standard module Globals
Use constands to hold sheet names and properties to retrurn sheet values
eg I have two name dranges, "main.date" and "main.server" on my sheet called
"main"

In the Globals module I have two constands with these two names and read
only properties to fetch them:
Option Explicit
' module: Globals
' Purpose : Return sheet data
Private Const BUSINESS_DATE As String = "main.date"
Private Const SERVER_NAME As String = "main.server"
Public Property Get BusinessDate() As Date
BusinessDate = CDate(Names.Item(BUSINESS_DATE).RefersToRange.Valu e)
End Property
Public Property Get ServerName() As String
ServerName = Names.Item(SERVER_NAME).RefersToRange.Value
End Property

In another module, called Module1, I show how to use the properties:
Option Explicit
Sub demo()
MsgBox "using" & ServerName & " for " & BusinessDate
End Sub
As you can see, properties, like functions, can be used as if they are
variables.

HTH




"kishore" wrote:

Hi,

I am working on project, and wanted to define a list of variables which
should be called by the macro. Is it possible to define the all
variables in one sheet, say Input, and when macro execute it takes the
necessary values from this sheet. The idea is when we use this Excel
File for other project, I just need to change the variables on this
Input sheet...and the macros remain still valid. Till I used to change
these variables in the macro before running them. Any thoughts how to
do it and how to call these values in Macro.

Many thanks...any help highly appreciated!!!

Regards,
Kishore


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default How to define variable

Thanks Guys, It works!!

Regds

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
Define Variable Name using VBA GTReferee Excel Discussion (Misc queries) 2 January 21st 09 06:37 PM
Using a Variable to Define Series Posse John Charts and Charting in Excel 2 August 30th 06 01:18 PM
Define Object Variable al Excel Programming 7 October 9th 04 08:03 PM
Define an array with variable size Yiu Choi Fan Excel Programming 3 July 9th 04 11:29 AM
Define variable range acberry Excel Programming 2 May 12th 04 02:44 PM


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