Change width of data validation dropdown - excel

In my workbook, cells AR8:AS8 are merged and in the cell is a data validation dropdown list. The source of the list uses the formula =indirect(GG8) and this refers to lists in a different tab.
My problem is that when I click on the dropdown, the box isn't wide enough to show the full item.
Is there any way of changing this? I would prefer to NOT use VBA if possible..
I look forward to your responses :)

There is no possible way to achieve this W/O VBA. if you wish to use VBA solution, then please find code below. You have to paste this code to your Worksheet module, not Regular module, and adjust based on comments.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Target.Address = "$H$1" Then 'adjust this range to your drop down list
Target.Columns.ColumnWidth = 30 'adjust to your needs
Else
Columns(8).ColumnWidth = 8 'adjust column number to column with drop down values
End If
End Sub
When dropdown is not selected:
Dropdown selected:

Related

Automatically set optimal height of visible columns in Excel

I have a fairly large Excel sheet, but I'm only interested in a certain amount of columns at a time. Now some columns contain quite a long text requiring a large cell height. After hiding these columns I wanted to set the cell heights of the visible rows rescaled to the optimum height for better browsing my sheet.
How can these be achieved in Excel either out-of-the-box or with a special rescale VBA Macro?
I'm not an Excel specialist, so any help is welcome her.
You probably have set the cells having long text to "Wrap Text". If you reset this, text is shown in one row now matter how long the content is.
If you do this for all columns that are hidden, Excel is able to calculate the needed height properly:
Sub setheight()
Dim col As Range
For Each col In ActiveSheet.UsedRange.Columns
' Set WrapText to false if column is hidden
col.WrapText = Not col.Hidden
Next
ActiveSheet.UsedRange.EntireRow.AutoFit
End Sub
Unfortunately there is no easy way to trigger this automatically as there is no event that is fired when a column is shown/hidden (yes, there is one, but this is related to the ribbon. If you want to have a look, see Trigger Event in Excel VBA when Row or Column is hidden)
There are numerous ways to trigger the sub, you could for example create a keyboard shortcut to the macro. An alternative that I use sometimes is to create a trigger on DoubleClick on a specific cell or range. I would suggest to run the code when the top row is Double-Clicked. Put the following code into the Worksheet-module
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Row > 1 Then Exit Sub
setheight
Cancel = True
End Sub

How to repeat command button in each row in excel

I'm creating a table in excel where the user can use a command button to create a clickable link to a document.
The table has various formulas to calculate dates etc. and it is an excel table, not a range of cells in excel.
So far I have copied the button for about 100 rows.
How do I get the file link button to repeat for each row?
Without the need of a CommandButton, the Code below combines Worksheet_SelectionChange and Intersect to create the link in the selected cell inside a specified Range as you click on it.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(ActiveSheet.Range("X3:X400"), Target) Is Nothing Then
ActiveSheet.Hyperlinks.Add Anchor:=Target, _
Address:="hhtp:\\YourLinkAddress.org", _
TextToDisplay:="Link"
End If
End Sub
Modify it to your Needs. You will get the values of the Row by using Target.Offset

Hide the cell selection box in Excel

I was wondering if there was any way to hide which cell you have selected within excel (for presentation purposes). I want the cursor itself (to navigate), but I want the box that highlights which cell i am clicking on invisible if possible.
Thanks!
If you're using a button object on your worksheet, it shouldn't highlight any cell. If you're using a cell as a "button", your best bet would be to hide and not use column A on your worksheet and then create a module:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("A1").Select
End Sub
which will select the now hidden cell A1, and hopefully no one notices...
There's no way that I know of to hide the box around the ActiveCell. However, you can create the same end result by placing the ActiveCell off screen (out of site of the user) and scrolling to the section of the screen that you want the user to see.
Cells(1000, 10000).Select 'Selects a cell that's far from the working area
ActiveWindow.ScrollColumn = 1 'scrolls to Column 1
ActiveWindow.ScrollRow = 1 'scrolls to Column 2
Now you've got a nice clear sheet without the selected cell box cluttering things up.
What I do is put the Selection Box in a Hidden Range. That effectively "hides" it from the user, because it is part of a range that cannot be seen.

Link Excel Cell to redirect to a sheet of same name

Good day,
I a new to VBA/Macro's and I am working in Excel. What I need to do is take a value in a specific cell (A4) and use that obtained value to go to a sheet in the same workbook with the same name. Thus in my dropdown in cell A4 I have 8 different options and dependent on this I need to go to a sheet with the same name.
Please help.
Assuming it is a Data Validation DropDown placed in the Excel Worksheet cell "A4", refer to the following VBA code snippet to achieve the result (i.e. switch to the Worksheet on DropDown select event):
Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$4" Then
Worksheets(Range("$A$4").Value).Select
End If
End Sub
Hope this may help.

Excel filter from other list

I have 2 lists in excel. First one is for searching (i want to have dropboxes), and second list is for data.
In second list I have filtered data. But what I want to do now is filter from parameters given in first list.
How can I transfer filter headers on first page?
I want to select brand on 'Search' list and results will be filtered on 'Rows' list.
I can't think of a way to do this exact thing without VBA. Certainly would love to know if there is a way, so maybe someone else can chime in.
That said, here is a small VBA procedure that will get what you want. It works based off a change in the drop down box for Brand in your Search sheet. Follow steps below to implement:
once in Excel hit Ctrl + F11 on your keyboard. This opens up the VBE
In the Project - VBAProject window in the upper left click the Object referring to the Search sheet
Paste the below code into the big window on the right referring to that sheet.
Make sure to save the file as an .xlsm file (Excel-Macro Enabled File) if using XL2007 or greater.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim wksFilter As Worksheet, wks As Worksheet
Dim rngFilter As Range
'replace "A6" with the cell where the Brand dropdown is
If Target.Address = "$A$6" Then
Set wks = Sheets(Target.Parent.Name)
Set wksFilter = Sheets("Rows")
'may need to adjust the number 1 to match the exact location of your Search Column in the rows sheet
wksFilter.UsedRange.AutoFilter 1, wks.Range(Target.Address)
End If
End Sub

Resources