Home > database >  Copy 2D array to another Vba module
Copy 2D array to another Vba module

Time:11-17

Hello ı created tableData() 2d array in named "list" module by getlist() function. I want to copy tableData() array to main sub. I think firstly ı have to call and run function in main sub afterwards copy. But ıdk how to do it could you help me? I hope problem is clear.

'list module
Public Function getlist()
Dim tableData() As String
End Function

'Main Module
Sub Main()
Dim partlist() As String
partlist() = list.tableData() ' ıdk :)
End Sub

CodePudding user response:

No need to use global variables.

(1) You need to assign a return value to a function. In VBA, this is done by assigning the return value to the "function" itself.

Public Function getlist() As String()
    'any operations with array tableData() 
   Dim tableData() As String
   (...)
   getlist = tableData
End Function

(2) When you call the function, assign the return value to your main procedure

Sub Main()
   Dim partList() As String
   partlist = getlist
   (...)
End Sub

CodePudding user response:

Public tableData() As String
Public Function getlist()
'any operations with array tableData() 
End Function

Sub Main()
Dim partlist() As String
partlist() = list.tableData() ' ıdk :)
End Sub

CodePudding user response:

Public tableData() As String
Public Function getlist()
  'any operations with array tableData() 
End Function

Sub Main()
    Dim partlist() As String
    Call list.getlist
    partlist() = list.tableData()
End Sub
  •  Tags:  
  • vba
  • Related