Static variable vs Function [Excel 2003]

Dynamo Nath

Board Regular
Joined
Aug 5, 2009
Messages
142
I've been reading a book and came across Static variables and was wondering what the pros and cons are of using a such a variable versus calling a function each time the value is required. My code currently calls a function each time.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You code calls a function to do what? Can you show your function code?
 
Upvote 0
It counts how many lines have been imported from a separate spreadsheet. That figure is then to select that data area and/or specific columns throughout the rest of the code. Each time the number is needed, I call the function. Everything works ok but I was wondering if using static variables would better/neater/quicker etc.

Code:
row_count = ActiveSheet.Range(cnst_wo_no & cnst_header_row, _
    ActiveSheet.Range(cnst_wo_no & cnst_header_row).End(xlDown)).Rows.Count + cnst_header_row - 1
 
Upvote 0
I'd say to store your row_count as a Public variable. Set it up once with a single call to the function, and then reference it as a variable after that.
 
Upvote 0
What would be the difference between a static and a public variable? They sound like they do almost the same thing...
 
Upvote 0
Not quite ... as far as I know Static means that variables in called functions will remain the same between calls while the main code is still running. Public means that variables will remain between runs of the main code. I may be wrong ... there are plenty of experts on here who may correct me on this.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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