Show Range of Cells based on Cell value (multiple cell values or buttons) Excel VBA


I want to display/show columns based on cell values or button commands VBA Eg : I am trying to compare monthly sales values for the period Jan to Dec via VBA Code, I want to show only two columns (range of columns) for two months which I am comparing among 12 months. So if I want to compare March and April, I would select March In cell A2 and April cell B2, and macros/code should show only range of cells based on these two cell values (A2= March and B2= April ) which would be March sale ranges, and April Sales ranges (column headings) and so on. I have tried to write the code as follows but I am not able to show two ranges of cells together ..

Sub RevHideColumnsHR1()
Select Case Range("D4").Value
Case "January"

Selection.EntireColumn.Hidden = True

End select
End sub

Once it shows correct range of columns, I also want to give simple difference formula for visible columns cells only (sale values for each customer in Mar and April) the variance range of columns would be fixed but only considering visible columns/cell values for calculation purpose



It sounds like should use use the Filter features of Excel. Can you include a sample file? Just update the original question to include on and it will then be easier to help you.
don (rep: 1247) Aug 3, '16 at 2:43 pm
I want more of CODE with which I can select column and column ranges to show and hide unwanted columns. I can then assign such code to individual buttons or create drop down menu with active x controls. Select desired range of columns for eg Jan, Feb March to show. The code should also show multiple columns based on choice. Eg if I want to see Jan, Feb or March. Or Jan and Feb together, Jan to April, it should display accordingly
ExAccounting (rep: 2) Aug 4, '16 at 7:48 am
Add to Discussion

Answer the Question

You must create an account to use the forum. Create an Account or Login