1

I have one sheet with VBA code with many variables and constants and I would like to use those variables even in VBA code of another sheet. Unfortunately code is split between sheets and requires shared variables and constants as input parameters. Is it possible in VBA for excel?

1
  • You should declare the variable in module level .. as Public Commented Aug 1, 2013 at 7:17

2 Answers 2

1

Yes, you must declare variables as Public variable [As type]. As @matzone said, at module level, i.e., before any subs, functions or properties.

In case of variable duplication you must refer to it as module.variable, where module is module code name as Sheet1 or ThisWorkbook.

Consider also the option of inserting a module in your VBA project to join all those shared variables (and functions, subs).

Sign up to request clarification or add additional context in comments.

Comments

0

Public token As String can access from other sheets, here token is variable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.