Losing the Values of my Publicly Declared Variables

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I ran into a situation ....

I have several variable declared publicly...
Code:
Public df_base As String, df_pitch As String, df_bb As String, df_cl As String, df_sm As String, df_sb As String, df_pc As String, df_rl As String, df_sl As String, df_cb As String, df_o1 As String

For the purposes of diagnosing my problem, I've added a watch for df_base. As I start stepping through my code in module 1, df_base = "". A routine is called from module 1 in module 2. That routine calculates a value for df_base. The correct calculated value of df_base, 75', is displayed in the watch box for that value. That routine finishes and we are returned to module 1 to resume where we left off. The remainder of the code displays the values of the worksheet. As we resume in module 1 where we left off, df_base still equals 75'.

However, when it reaches the line to display the value in the cell, nothing is populated. When hovering over df_base, it indicates =""

I don't understand why the values of my variables (all of them declared publicly) fail to populate their cells. Here is a portion of the display code:

Rich (BB code):
    With ws_form
        'populate
        mbevents = False
        .Unprotect
        If rcode Like "D*" Then
            With .Range("K8")
                .Validation.Delete
                .Value = df_base  'df_base = "" although in the watch it says 75'
                .Validation.Add Type:=xlValidateList, Formula1:="=nm_base"
                If .MergeCells = True Then
                    Set mergeRange = .MergeArea
                    If prow <> 0 Then
                        mergeRange.Locked = True
                    Else
                        mergeRange.Locked = False
                    End If
                End If
            End With
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
could you change
With .Range("K8")

to
with sheets("name").range("K8") wondering if the code is loosing track of where it is
 
Upvote 0
Hi mole. Thank you for your help. I added the sheet reference to all the ranges as you had suggested and it hasn't resolved the problem unfortunately.
I realized then that I still had those variables declared at the module level during creation. Removed them, all all working as hoped.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,318
Members
453,032
Latest member
Pauh

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