SeniorNewbie
Board Regular
- Joined
- Jul 9, 2023
- Messages
- 77
- Office Version
- 2021
- 2019
- Platform
- Windows
- MacOS
Hi XLperts out there!
there's a module created by VBA named "mdl_DynARR". It shall contain dynamically created arrays with data samples. With my first result it looks like this:
created by:
Don't ask how many hours I was fighting with this **ucked """""" to make this run
Okay - what's my question? In code paragraph one you can see a first result, in code paragraph two you see an if...then. That should trigger the next step: What I want to do is, to modify the code of paragraph one, line two to Public aTest, aTest2, aTest3 and so on. To add the next array is no problem. Modify is the subject
Is there any chance?
THX a lot! and enjoy the weekend!
Senior Newbie
there's a module created by VBA named "mdl_DynARR". It shall contain dynamically created arrays with data samples. With my first result it looks like this:
VBA Code:
Option Explicit
Public aTest
Sub PopulateTest()
aTest = Array("Test_1", "Test_2", "Test_3", "Test_4", "Test_5")
End Sub
Code:
Sub ArrayTest()
Dim sName As String
sName = "Test"
AddArray sName
End Sub
Sub AddArray(sName As String)
System 'defines some publics like workbook, ~sheets etc.
Dim sPublic As String, sArray As String, sItem As String, iLines As Integer, i As Integer
With wb.VBProject.VBComponents("mdl_DynARR").CodeModule
If Left(.Lines(2, 1), 8) = "Public a" Then
MsgBox "!"
Exit Sub
End If
End With
sPublic = "Public a" & sName
sArray = " a" & sName & "=Array("""
For i = 1 To 5
sItem = sName & "_" & i & """" & "," & """"
sArray = sArray & sItem
Next i
sArray = Left(sArray, Len(sArray) - 2) & ")"
With wb.VBProject.VBComponents("mdl_DynARR").CodeModule
iLines = .CountOfLines + 3
.InsertLines iLines, sPublic: iLines = iLines + 1
.InsertLines iLines, "Sub Populate" & sName & "()": iLines = iLines + 1
.InsertLines iLines, sArray: iLines = iLines + 1
.InsertLines iLines, "End Sub": iLines = iLines + 1
End With
End Sub
Okay - what's my question? In code paragraph one you can see a first result, in code paragraph two you see an if...then. That should trigger the next step: What I want to do is, to modify the code of paragraph one, line two to Public aTest, aTest2, aTest3 and so on. To add the next array is no problem. Modify is the subject
Is there any chance?
THX a lot! and enjoy the weekend!
Senior Newbie