Autofit rows based on Slicer selection

Ex_Newbie

New Member
Joined
Aug 5, 2019
Messages
2
Hello Excel Gurus!

I am trying to create an interactive dashboard using Slicers, Pivot tables/charts and Index/Vlookup functions. There is a section where I am using INDEX to lookup text based on a Slicer selection (which I have linked in my INDEX formula). The text varies in length based on my Slicer selection so I selected Wrap Text in the cell and Autofit Row Height but the the row height doesn't change as my Slicer selection changes. I spent hours (maybe days) googling how to fix that problem and the only thing I came up with was using VBA to do this:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)


Range("V4:V7").Rows.AutoFit


End Sub

The problem with this is the row heights don't change unless I click on a cell on the spreadsheet to trigger the event. Now since this is a dashboard that will be sent to other users and I don't want to have them do that after filtering with Slicer. I am totally not versed with VBA at all. :confused: So I want to know what can I add to the code to have the row heights change automatically once the selection is made with the Slicer?

Thanks so much for any advice!!!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Changing the slicer should refresh the pivot. So run the event off that.


Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
 [COLOR=#252C2F][FONT=Courier]End Sub
[/FONT][/COLOR]
 
Upvote 0
Thanks @mrshl9898. I actually got it to work with the Calculate event:

Private Sub Worksheet_Calculate()


Range("V4:V8").Rows.AutoFit


End Sub

But now the rows look kind of tight, what is the code to add some extra height to the rows after autofit is done?

Thanks.
 
Upvote 0
Something like this should fit your purpose


Code:
With Worksheets("Sheet1").Rows(4)
 .RowHeight = .RowHeight + 2
End With
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,580
Members
452,653
Latest member
craigje92

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