excel vba constant

' Constants are Private by default. 
Const MyVar = 459 
 
' Declare Public constant. 
Public Const MyString = "HELP" 
 
' Declare Private Integer constant. 
Private Const MyInt As Integer = 5 
 
' Declare multiple constants on same line. 
Const MyStr = "Hello", MyDouble As Double = 3.4567

4
8

                                    'In VBA, GLOBAL variables must be declared ABOVE all procedures in a module:

Public MyGlobalString As String				'<-- global to ALL modules
Private MyGlobalLong As Long				'<-- global to THIS module (Private)
Public Const HELP As String = "Press F1"	'<-- global to ALL modules

Sub Add(a, b)
	MyGlobalLong = a + b
End Sub

Call Add(7, 2)			
MsgBox MyGlobalLong		'<--displays: 9
MsgBox Help				'<--displays: Press F1

'
'
'

4 (8 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
vba globale variable excel vba how to set global variable initialize global variable vba excel vba constant global variable visual basic excel global variables how to declare constants in vba constants vba excel vba how to use global variable excel vba global variable set value What are global variables in vba vba excel variable globale excel vba how to set global variables declaring global variables in vba global variable worksheet vba variable global vba vba excel global variable initialization constants in VBA ms excel vba constant object ms excel vba constants vba global variables in module excel vba global function vba constant string excel vba set global variable excel vba global constant excel vba initialize global variable excel vba make global variable vba set global variable value vba use global variables excel vba constant expression required vba constant access vba develop a global variable excel set constant value from formula vba constante excel vba Global Variables VBA excel vba constants global variable in vba excel declare global variable in vba vba declare constant excel loop through global variable excel global variables winwrap basic declare constate constant vba excel vba store constants xcel vba store constants excel vba constant vba public const vba class public const how to declare constant global variables using vba how to store global variables using vba excel declare constant vba store global variable xl-vba global vs public xl vba global vs public xlvba global vs public excelvba global vs public excel vba global vs public vba global vs public vba declare globals excelvba declare globals excel vba declare globals xl vba declare globals xl-vba declare globals xlvba declare globals xlvba declare global constant xl-vba declare global constant excel-vba declare global constant excel vba declare global constant excelvba declare global constant vba declare global constant vba declare global variables vba declare global variable vba set global variables variable global macro excel how to make a variable visible to all sub and functions in vba global variable in vba how to make a variable global in excelvba global variables excel vba class global variable vba excel global module excel macro global variable vba global variables excel vba global variable initialize declare global variable vba pass a global variable vba outlook module global variable vba using global var vba excel global var vba vba excel global variable vab global variable Set global vba how dim a variable global excel vba global variable use global variable from another module vba excel vba dim global variable global variable vba global variables vba global variables in vba vba overwrite global variable vba global variable vba excel global variables vba how to declare a global variable excel vba how to declare a global variable
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source