Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49892

Public strings keeping values after a macro is completed

$
0
0
Hello everyone!

I am having issues with a few of my public variables that are keeping the values of that were stored in them in the last run (Excel wasn't closed).

How do I reset the values, without having to do s_Test1 = "" for each string?

Here is an example, If I run this macro two times, it keeps the values form the first run and shows x2 values in the second run:

Code:

Option Explicit
Public s_Test1 As String
Public l_ForLoop1, l_LastRowCount1 As Long

Sub sb_Test1()

l_LastRowCount1 = Wks_Tmp2.Cells(Rows.Count, "A").End(xlUp).Row

For l_ForLoop1 = 1 to l_LastRowCount1
  IF s_Test1 = "" Then
      s_Test1 = Range("A" & l_ForLoop1).Value
  Else
      s_Test1 = s_Test1 & vbCrLf & Range("A" & l_ForLoop1).Value
  End If

Next

Msgbox s_Test1

End Sub


Viewing all articles
Browse latest Browse all 49892

Trending Articles