I would like to make an excel with VBA file which gets an input from the user 1,2 or 3 :
-
How can I run it while opening the
xslmfile ? -
Assuming I have this table in my file:

the common data is useful for column A B and C unique content.
I would like to use the code bellow, so depends on the user input, it will select the unique data from A,B or C to the place of A's unique data. BUT I want that the data of column A will be reusable for future use, e.g. if the user will provide input_num=1 so the data will be A's unique data
Sub main()
MsgBox ("welcome")
Dim input_num As Integer
input_num = InputBox(Prompt:="please select device", Title:="select device", Default:=3)
If input_num = 1 Then
' use the first column
ElseIf input_num = 2 Then
' use the second column
Else
' use the third column
End If
End Sub
To run the code when the Excel file starts you can use
Any code that you will put here will run provided macros are enabled in your file. For example, you will see a message box “Hello World” when you open the file which has the below code.
The
Workbook_Open()goes in the Workbook Code area as shown in the screenshot belowNow regarding your 2nd question
In Excel, you can refer to columns not only by names but also numbers so for example
Column A can be referred to as
or
This makes your job easier as you can now directly refer to the column based on the user input. For example