Share via

Visual Basic configuration datas

Mehdi Rajabali 20 Reputation points
2024-01-13T14:53:42.8366667+00:00

Hello Rescue Team I want to use code to write code in VB, For example I want to declare dynamic public data/variable/name depended on what I got from my user forms , in terms of using them by other workbooks. Thank you!

Microsoft 365 and Office | Development | Other
Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

Answer accepted by question author

Azar 31,720 Reputation points MVP Volunteer Moderator
2024-01-14T03:13:47.51+00:00

Hey Mehdi Rajabali I guess you can use dynamic arrays: ex- below for you

' Assuming you have a form where the user provides the variable names Sub CreateDynamicVariables()     Dim userInput As String     Dim dynamicVariables() As Variant     Dim i As Integer      ' Get user input (variable name)     userInput = InputBox("Enter a variable name:")      ' Check if the user entered a variable name     If userInput <> "" Then         ' Check if the variable already exists         For i = LBound(dynamicVariables) To UBound(dynamicVariables)             If dynamicVariables(i) = userInput Then                 MsgBox "Variable already exists!"                 Exit Sub             End If         Next i          ' If the variable doesn't exist, add it to the array         ReDim Preserve dynamicVariables(0 To UBound(dynamicVariables) + 1)         dynamicVariables(UBound(dynamicVariables)) = userInput          ' Now you have a dynamic array of variable names         ' You can use this array for further processing or store values in corresponding variables         MsgBox "Variable added: " & userInput     Else         MsgBox "No variable name entered!"     End If End Sub 


If this helps kindly accept the answer thanks much.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.