Global Variable Scope/Value Assignment

fuzzyaces

New Member
Joined
Sep 13, 2011
Messages
5
All,

I am trying to write a simple piece of code and across multiple procedures, I'm trying to find the bottom row of a range (e.g.

Code:
Cells(65536, 1).End(xlUp).Row

I'm not having any troubles with this. My question is that to simplify the code, and to speed up changes, is there a way I can make a global variable (e.g. mlBottomRow) at the initial declaration AND set the value? For example:

Code:
Option Explicit
Dim mlBottomRow as Long
mlBottomRow = 65536

Sub Procedure1()
    Code...
End sub

Sub Procedure2()
    Code...
End sub

I know in variable scope, I can dimension the variable and type. I'm just unclear on actually setting the value outside a procedure.

Thanks for your help!

-Fuzzy
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Fuzzy

Do you mean you want to declare the no of rows in a worksheet, eg 65536, to use when you want to find the last row of data?

Why not just use Rows.Count?

That will return the no of rows in a worksheet for whichever version of Excel the code is in.
 
Upvote 0
All,

Nevermind. I searched and found that others had previously answered this question. It appears a minor modification is needed:

Code:
Public Const mlBottomRow as Long = 65536
 
Upvote 0
Fuzzy

Do you mean you want to declare the no of rows in a worksheet, eg 65536, to use when you want to find the last row of data?

Why not just use Rows.Count?

That will return the no of rows in a worksheet for whichever version of Excel the code is in.

Norie,

That's a much smarter route than I've been considering with the rows example, but there were a few other values I wanted to constrain. In any event, thank you for your help. It's much appreciated.

-Fuzzy
 
Upvote 0
Fuzzy

What other values do you want to 'constrain'?
 
Upvote 0
I know they're kind of restrictive but why not just use the builtin vbRed, vbBlue etc and the ColorIndex palette?

Or are you going a bit beyond that?
 
Upvote 0
I know they're kind of restrictive but why not just use the builtin vbRed, vbBlue etc and the ColorIndex palette?

Or are you going a bit beyond that?

Sigh. I would love that, but unfortunately, I have a specific RGB color scheme to follow.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,603
Members
449,038
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top