Macro

jbodel

New Member
Joined
Jun 2, 2014
Messages
47
Office Version
  1. 365
Platform
  1. Windows
I have what I hope can be done, where I have a button at the top of the Worksheet, that says Print Friendly. Right now it hides certain columns, but after talking to certain co-workers they need it to have an option to print or hide certain columns. So when you click on the button it asks which columns to hide and then prompt them for the Print queue. Now if it could ask them the columns name it would be fantastic, but if it has to say , Column A, B C, etc, that is okay as well. Note that these column headers are on row 15.
Screenshot 2025-03-20 104113.png


Is this possible? I am no expert in excel but is there a VBA that you might be able to share that could get me started?
 
Will the columns that need to be hidden always be the same for each user? If so, they can simply record their actions using the macro recorder and save it. That's a feature built into Excel. Very simple & easy. If it varies time to time, then that's also possible - but first you should provide some more details.
 
Upvote 0
The columns will remain the same, but each user might decide to hide and print different columns. I knew about the record function, but one user might want to hide the AFP Code Column only while another might want to hide The AFP Code, Service Code and Quote price
 
Upvote 0
Do you mean something like this?

This will ask the user to select the headings they want to hide. This is done by selecting with the mouse. You can select individual headings by pressing the Ctrl key.

VBA Code:
Sub Button1_Click()
    Dim ColumnsToHideRNG As Range
    On Error Resume Next
    Set ColumnsToHideRNG = Application.InputBox(Prompt:="Select the cells with the desired headings" & vbNewLine & "Hold down the Ctrl key to select individual titles." & vbNewLine & "To unhide the columns, close this window.", Type:=8)
    On Error GoTo 0
    Dim Col As Variant
    If Not ColumnsToHideRNG Is Nothing Then
        For Each Col In ColumnsToHideRNG.Columns
            Col.EntireColumn.Hidden = True
        Next Col
    Else
        ActiveSheet.UsedRange.EntireColumn.Hidden = False
    End If
End Sub


My apologies for any quirks, English is not my native language. "So I blame Google translate for all my goofs." :devilish:
 
Upvote 0
Solution
OK, I want to try this, but since I am still a beginner in excel, this is the current macro I have (which I just used the record macro option) but what do I need to change to match yours?



FYI - I think Google did a good job of translate.

Screenshot 2025-03-20 155158.png
 
Upvote 0
1. Make a copy of your workbook and paste my macro there.
2. Select the desired sheet and run the macro, it will ask you to select the headers whose columns you want to hide.
The selection is made with the mouse.
You will see how it works and then you can consider whether it is suitable for your purpose.
 
Upvote 0
1. Make a copy of your workbook and paste my macro there.
2. Select the desired sheet and run the macro, it will ask you to select the headers whose columns you want to hide.
The selection is made with the mouse.
You will see how it works and then you can consider whether it is suitable for your purpose.
That worked. Thank you very much. I appreciate your time and patience.
 
Upvote 0
Nice to hear we were able to help and thanks for the feedback!
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top