+ Reply to Thread
Results 1 to 10 of 10

Wildcard for macro

  1. #1
    Registered User
    Join Date
    08-11-2014
    Location
    USA
    MS-Off Ver
    2013 Pro
    Posts
    26

    Question Wildcard for macro

    I have about 20 columns on a sheet that contain different data in the exact same rows. I have a macro to clear the data from a particular column:

    Please Login or Register  to view this content.
    This is tied to a button form control on the sheet that says 'Clear Data'. Rather than creating a form control and macro for each column, is there a method to have a user either input a column letter in a cell or select from a dropdown in the cell and then have the macro use that cell to replace the column letter in the code. So the code would be setup with a wildcard entry and based on the input from the cell it would replace the column letter in all of the code? For example the entry cell would be AV2 and the user enters 'E' and then click the button form control and the macro would run as:

    Please Login or Register  to view this content.
    thanks

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Wildcard for macro

    I think this will do what you want
    Please Login or Register  to view this content.
    Last edited by mikerickson; 08-29-2014 at 10:13 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,904

    Re: Wildcard for macro

    Try this code:
    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,486

    Re: Wildcard for macro

    Untested, but try:

    Please Login or Register  to view this content.

    Regards, TMS
    Last edited by TMS; 08-29-2014 at 10:20 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Registered User
    Join Date
    08-11-2014
    Location
    USA
    MS-Off Ver
    2013 Pro
    Posts
    26

    Re: Wildcard for macro

    Stupid question, when you enter the title for the InputBox into a cell which direction does the macro search for the data? Cell in the row below, cell in the column to the right,...? Or is there a method to designate the InputBox?

  6. #6
    Registered User
    Join Date
    08-11-2014
    Location
    USA
    MS-Off Ver
    2013 Pro
    Posts
    26

    Re: Wildcard for macro

    Disregard, apologies.

  7. #7
    Registered User
    Join Date
    08-11-2014
    Location
    USA
    MS-Off Ver
    2013 Pro
    Posts
    26

    Question Re: Wildcard for macro

    Thanks for all of the replies. I ended up going with this:

    Please Login or Register  to view this content.
    But I want to see if I can take it a step further and eliminate user error because it may result in formulas being cleared if the wrong column is entered.

    I have a list of Customer Names in Row 6 (Customer 1, Customer, 2, etc.) and the same column contains the data I want cleared (Customer 1 Column D, Customer 2 Column F, etc.). There are formulas in the columns between the Customer Names (Column E, Column G, etc.). So how would I get a ComboBox working to have a dropdown selection of the Customer Name from Row 6 and match it to the column where is exists and clear the entries based on that particular column? Also I don't have a header or title stating the Customer Name row, they only exist in each particular cell.

    If Customer 1 (D6) was selected then it would clear contents in D11:D16,D18:D47,D49:D85,D87:D107,D120:D150. Customer 2 (F6) would clear contents in F11:F16,F18:F47,F49:F85,F87:F107,F120:F150. And so on.

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,904

    Re: Wildcard for macro

    I would do data validation as shown in the attached in a column. Then in an adjacent cell, I do a vlookup and make that cell your input variable col. See the attached spreadsheet and VBA in the spreadsheet.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-11-2014
    Location
    USA
    MS-Off Ver
    2013 Pro
    Posts
    26

    Re: Wildcard for macro

    I ended up working kind of a hybrid of what you had suggested. I populated the column headers into a table starting in BD3 and copying down to BD23 using:

    =INDEX($C$9:$AR$9,INT(2*ROWS($BD$3:BD3)))

    Then I created a named list (clist) based on those entries plus an extra at the top (BD2) for All Columns. And used a ComboBox to display the named list in a drop down. When you chose an entry from the drop down it populates a linked cell (BA3). Then I extract the column letter from the entry in the linked cell to BB3 using:

    IF(BA3="all columns",1,LEFT(ADDRESS(ROW(A9),MATCH(BA3,9:9,0),4),LEN(ADDRESS(ROW(A9),MATCH(BA3,9:9,0),4))-LEN(ROW(A9))))

    Then inserted a Button Form Control to perform the following macro:

    Please Login or Register  to view this content.
    Workbook if you want to see further:example6.xlsm

    I will probably end up moving the helper table, linked cell and column calculations off to a 'data' sheet. So only the Button and ComboBox will remain on the existing sheet.

    Thanks for everything, got a bunch of great suggestions to get the sheet functioning properly.

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,904

    Re: Wildcard for macro

    Glad to have been helpful. Thanks for the Rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro - Wildcard Character
    By SVTF in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2013, 01:52 PM
  2. [SOLVED] Find: Using wildcard, but don't replace with wildcard
    By JimDandy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-06-2013, 05:39 PM
  3. Wildcard macro to move file
    By dave1983 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-22-2013, 06:35 AM
  4. [SOLVED] Building a macro with a wildcard
    By vanmeterkj in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-24-2012, 11:06 AM
  5. How do I add this wildcard to this macro?
    By jonathynblythe in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-03-2011, 05:38 PM

Tags for this Thread

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