Dear all
The workbook I am working with is set to be used with userforms only; there are around 20 of them. I have a number of variables of type byte which are repeatedly used in userforms.
Is it a good idea to create global variables, global constants or enum whose values are set when the workbook opens?
You probably wonder what the variables are used for:
I work with listobjects and in order to keep the whole workbook 'dynamic', I retrieve the column numbers ( based on the header name) and put them into a variable.
For example, the column 'Name' in the table 'Customers' is in column number 3. If a new column is inserted or deleted, I want to make sure that this variable matches/'adapts itself' to the correct column number. I use this number when working with arrays for example.
The function I use to retrieve the column number is:
For example, in order to set the variable ColumnCustomerName I use
Would you use global variables / enum or would this method use up, despite the fact that the variables are of type byte, too much memory?
Thanks
Maria
The workbook I am working with is set to be used with userforms only; there are around 20 of them. I have a number of variables of type byte which are repeatedly used in userforms.
Is it a good idea to create global variables, global constants or enum whose values are set when the workbook opens?
You probably wonder what the variables are used for:
I work with listobjects and in order to keep the whole workbook 'dynamic', I retrieve the column numbers ( based on the header name) and put them into a variable.
For example, the column 'Name' in the table 'Customers' is in column number 3. If a new column is inserted or deleted, I want to make sure that this variable matches/'adapts itself' to the correct column number. I use this number when working with arrays for example.
The function I use to retrieve the column number is:
Code:
'-----------------------------------------------------------------
' Author Maria
' Date 5.1.2016
' Purpose Retrieves the column number - searches in a
' listobject header
' Requires string to search
' range (listobject name)
' Important needs range with [#headers], eg
' Range("RecyclingTaxiAufträge[#Headers]")
'-----------------------------------------------------------------
Function GetColumn(str As String, rng As Range) As Integer
GetColumn = Application.WorksheetFunction.Match(str, rng, 0)
End Function
For example, in order to set the variable ColumnCustomerName I use
Code:
ColumnCustomerName = GetColumn("Name",Range("Customers[#Headers]")
Would you use global variables / enum or would this method use up, despite the fact that the variables are of type byte, too much memory?
Thanks
Maria