+ Reply to Thread
Results 1 to 12 of 12

Macro Enabled VBA code to hide table column

  1. #1
    Registered User
    Join Date
    06-05-2019
    Location
    Boston
    MS-Off Ver
    Excel 2013
    Posts
    9

    Macro Enabled VBA code to hide table column

    Hi All,

    Looking for a way to hide the customers column in a table when the form control option button for item number is selected and vise versa. I tried to record myself and apply that as a macro but ran into problems. I also have this paired with a VBA search bar and there are many rows. Just trying to make it more user friendly. I think that formatting everything to match the background is the best way to do it, but the process of applying it has exceeded my knowledge.

    See attached example workbook.

    Thanks!
    Attached Files Attached Files
    Last edited by charliedumas42; 06-18-2019 at 02:38 PM.

  2. #2
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: Macro Enabled VBA code to hide table column

    here ya go, easy peasy
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    06-05-2019
    Location
    Boston
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Macro Enabled VBA code to hide table column

    dmcgov,

    Thank you for the help and quick response, but I guess I should have given a harder example.... Unfortunately, I can't just hide the whole column as there is useful information above. Also, the sheet will be locked with a password. Maybe you are up for this challenge???

    Let me know if you have any questions about my file!

    Best,
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: Macro Enabled VBA code to hide table column

    charlie

    don't know how to do this if i cant hide columns. maybe cycle through customers and items and assign them to array. then clear the range. i tried to use filters but that just hides rows so that won't work. are you familiar with array's?

  5. #5
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: Macro Enabled VBA code to hide table column

    so i cobbled this together and made array's out of the customers and item numbers. is that what you are looking for?
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-05-2019
    Location
    Boston
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Macro Enabled VBA code to hide table column

    I think that this may be as good as it gets. I really appreciate the help. Not too familiar with arrays, but I will try to reverse engineer what you did.

  7. #7
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: [SOLVED] Macro Enabled VBA code to hide table column

    do you need the background color to change? other than that, you should be good to go.

  8. #8
    Registered User
    Join Date
    06-05-2019
    Location
    Boston
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: [SOLVED] Macro Enabled VBA code to hide table column

    I think the way you hid the data should be enough to avoid confusion. Is there a way to run the "write customers" sub automatically after the "hide items" sub to avoid the extra clicking?

    The goal would be to populate one column and hide the other column simultaneously and be able to continuously switch back and forth.

  9. #9
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: [SOLVED] Macro Enabled VBA code to hide table column

    so add this code to the module and assign it to your "unhide" radio button

    Please Login or Register  to view this content.
    that should work for you.

    didn't understand what you wrote, but now i do. so add a CALL to the macro, like so:

    Please Login or Register  to view this content.
    do the same for hide_items
    Last edited by dmcgov; 06-18-2019 at 02:18 PM.

  10. #10
    Registered User
    Join Date
    06-05-2019
    Location
    Boston
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: [SOLVED] Macro Enabled VBA code to hide table column

    Ok, I will give that a shot

  11. #11
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: [SOLVED] Macro Enabled VBA code to hide table column

    if this works for you, please mark the thread as solved (top of post under thread tools) and if i have helped you in any way, please click the Add Reputation under my username.

  12. #12
    Registered User
    Join Date
    06-05-2019
    Location
    Boston
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Macro Enabled VBA code to hide table column

    UPDATE:

    I was having difficulty with the code to work consistently with my search function, so I ended up just changing the background of my cells to match a colorindex number and then wrote a code to change the font color of the text within the range. Sometimes simpler can be better! Big thanks to dmcgov for helping me through this.



    Sub hideitemnumbers()

    ActiveSheet.Unprotect Password:="password"
    On Error Resume Next
    ActiveSheet.ShowAllData

    Range("D29:D5000").Font.ColorIndex = 19

    Range("C29:C5000").Font.ColorIndex = 1


    ActiveSheet.Protect Password:="password"

    End Sub

    Sub hidecustomers()

    ActiveSheet.Unprotect Password:="password"
    On Error Resume Next
    ActiveSheet.ShowAllData

    Range("C29:C5000").Font.ColorIndex = 20

    Range("D29:D5000").Font.ColorIndex = 1


    ActiveSheet.Protect Password:="password"

    End Sub

+ 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. [SOLVED] How can I modify this code so it saves as a macro enabled file
    By TBM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-25-2018, 12:57 PM
  2. Workbooks.Open freezes excel...Macro-enabled and not Macro-enabled :(
    By IndesliciveMelon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2018, 05:48 PM
  3. Create macro-enabled worksheets with code in them
    By atiseni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2017, 09:58 AM
  4. [SOLVED] VBA Code to link macro-enabled workbook
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2016, 07:34 AM
  5. Replies: 6
    Last Post: 10-20-2014, 09:37 AM
  6. [SOLVED] Macro to hide last column in a pivot table
    By Shellybelly in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2014, 07:01 AM
  7. [SOLVED] Send via email macro enabled wrksheet (xlsm) as regular wrksheet (xlsx) using a macro code
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-30-2013, 09:26 PM

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