View Single Post
 
Old 10-01-2021, 02:45 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You can keep passing variables across functions but I think it is easier to declare a variable so it can be used by all the sub/functions in the module. This then persists and can be added to or read by any of the subs or functions. This illustrates the concept.
Code:
Option Explicit

Private arr1() As String, sArr As String

Sub TheLoop()
  Dim i As Integer
  sArr = ""       'this empties the string in case the macro was run earlier
  For i = 1 To 10
    TheTest i
  Next i
ThePayout:
  MsgBox sArr
  arr1 = Split(sArr, "|")
End Sub

Sub TheTest(i As Integer)
  If i Mod 2 = 0 Then
    TheLogger i
  End If
End Sub

Sub TheLogger(i As Integer)
  If sArr = "" Then
    sArr = "Item " & i
  Else
    sArr = sArr & "|" & "Item " & i
  End If
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote