+ Reply to Thread
Results 1 to 6 of 6

Deleting columns with dynamic user input

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-01-2019
    Location
    New York, New York
    MS-Off Ver
    Office 2016 for Mac
    Posts
    125

    Deleting columns with dynamic user input

    I have a general question. We do a lot of column deletion in our data and the specific columns that get deleted are different for each client's data. I am familiar with how to write a code that deletes specific columns (so we could write a separate code for each client and reuse). However, is it possible to create a VBA code that allows the user to select which columns to delete from a list/message box kind of thing and only write one code that works across clients?
    Last edited by Ianmacros; 04-16-2019 at 08:31 AM.

  2. #2
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,492

    Re: Is this possible in VBA?

    I'm sure it is..
    you could make a double click even where you the headerrow text is replaced by delete
    and then have a loop that will delete all columns with the word delete in row 1 (or whichever row is the header)

    best thing would post an example of how data will look before and how it will look after explaining what needs deleting and why.

    Depending on specific needs it can eighter be a simple code or a more complex code to go from client format to your desired import format, with field mapping to be setup

  3. #3
    Forum Contributor
    Join Date
    03-01-2019
    Location
    New York, New York
    MS-Off Ver
    Office 2016 for Mac
    Posts
    125

    Re: Is this possible in VBA?

    Thanks, Roel. This is the exact solution I suggested to my boss. However, I was advised that we ultimately have different column headers provided by each client. Since our clients change often, the header labels changes, which would mean continuously updating the code so it can loop through, replace with delete and delete any rows with delete in row 1. I know there's the inputbox function but that seems to be related to inputting data and performing operations versus something like deleting columns, which is closer to a formatting task. Any other suggestions?

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Is this possible in VBA?

    For multiple columns...

    Option Explicit
    
    Sub UserInput_Columns_Delete()
    Dim Arr As Variant, i As Long
    Arr = Application.InputBox("List the column numbers in the following format: " & vbCrLf & "{1, 2, 3}", Type:=64)
    For i = UBound(Arr) To LBound(Arr) Step -1
        Columns(Arr(i)).Delete
    Next i
    End Sub
    Last edited by Sintek; 04-15-2019 at 03:49 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  5. #5
    Forum Contributor
    Join Date
    03-01-2019
    Location
    New York, New York
    MS-Off Ver
    Office 2016 for Mac
    Posts
    125

    Re: Is this possible in VBA?

    sintek that is exactly what I needed!

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2503
    Posts
    13,702

    Re: Is this possible in VBA?

    Administrative Note:


    For future reference please attend to your thread titles. This thread title does not really convey what your request is about.

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.
    Dave

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1