Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8628995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:41:32+00:00 2026-06-12T08:41:32+00:00

I would like to make an excel with VBA file which gets an input

  • 0

I would like to make an excel with VBA file which gets an input from the user 1,2 or 3 :

  1. How can I run it while opening the xslm file ?

  2. Assuming I have this table in my file:

enter image description here

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:41:33+00:00Added an answer on June 12, 2026 at 8:41 am
    1. How can I run it while opening the xlsm file ?
    
    2. Using the column based on User input
    

    To run the code when the Excel file starts you can use

    Private Sub Workbook_Open()
    
    End Sub
    

    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.

    Private Sub Workbook_Open()
        MsgBox "Hello World"
    End Sub
    

    The Workbook_Open() goes in the Workbook Code area as shown in the screenshot below

    enter image description here

    Now 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

    Sheets("Sheet1").Columns("A:A")
    

    or

    Sheets("Sheet1").Columns(1)
    

    This makes your job easier as you can now directly refer to the column based on the user input. For example

    Private Sub Workbook_Open()
        MsgBox "welcome"
    
        Dim input_num As Variant
    
        input_num = InputBox(Prompt:="please select device", _
        Title:="select device", Default:=3)
    
        Select Case input_num
            Case 1, 2, 3
                With Sheets("Sheet1").Columns(Val(input_num))
                    '
                    '~~> Do what ever you want
                    '
                End With
        End Select
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an excel 2003 vsto workbook that I would like to make available
I would like make an extension method for the generic class A which takes
I would like to make my app freeware, but if a user is willing
I'm trying to make an application-level add-in for Excel and I would like to
In Excel I have a date field. I would like to make a button
I would like to make some AIR application which would be used for tracking
I have an existing business application written in Excel which the client would like
--I have some rows from my table which I would like to export in
I would like make a script using PHP (probably need JS) to send POST
Would like to make anapplication in Java that will not automatically parse parameters used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.