Adding Vlookup as hyperlink Tooltip Excel - Dynamic tooltips excel - excel

I was looking to create dynamic information on a cell when you don't have a lot of space but would like to display it.
I wanted to use on a job sheet to let the user know what the job No. referred to if their not familiar with it.
I used the hyperlink method combined with vba to achieve self updating list.
This is the hover over I wanted.
https://superuser.com/questions/1296838/customize-hyperlink-hover-over
But i wanted it dynamically updated from a table where I could update the table and it would pull the information and add the tooltips as descriptions.

So the solution is this
Sub toolmicro()
'
' toolmicro Macro
Dim rng As Range: Set rng = Application.Range("Sheet1!C2:C30")
Dim cel As Range
For Each cel In rng.Cells
With cel
If cel.Value = "" Then
Else
Dim tooltiptoolmine As String
tooltiptoolmine = Application.WorksheetFunction.IfError(Application.VLookup(cel.Value, Sheet1.Range("A1:B3"), 2, False), "Add Description to job")
cel.Hyperlinks.Add Anchor:=cel, Address:="", ScreenTip:=tooltiptoolmine
End If
End With
Next cel
End Sub
The Range looks for a set of cells to add the if to you could make it a column like C:D.
It skips blanks
Has error handling if the description hasn't be written yet.
Applys the link based on vlookup.
Then to get it to automagically update as I add jobs to the list
This will look for a change on the worksheet and call the list update.
Private Sub Worksheet_Change(ByVal Target As Range)
Call toolmicro
End Sub
If anyone has a better way let me know.

Related

Copying selected table repeatedly when clicking button

I'm trying to create a repeated copy and paste of a table I have in one of my worksheets and assign it to buttons in my budget worksheet.
For example whenever you click on the contract button, it will install the new table. Click it again, it will leave a line break and insert the new table. Same thing with the variation button.
Budget worksheet
Table sample
My attempt in a related copied sample in one of the questions asked here.
I understand to copy and paste I've been told to use this code
Sub CopyPasteToAnotherSheet()
Worksheets("Dataset").Range("B2:F9").Copy Worksheets("CopyPaste").Range("B2")
End Sub
It works, but I can only copy it once. I don't know how to copy it numerous times each time I run the macro.
Welcome to stack!
So I think I understand the want, it's usually good to have a go and show us the code you have but as its the first time here's a start of a code that might do that:
Sub variations()
Dim rng As Range
Set rng = ActiveWorkbook.Sheets("Variations").Range("A1:B5")
Run copyAcross(rng)
End Sub
Sub contracts()
Dim rng As Range
Set rng = Worksheets("Contract").Range("A1:B2")
Run copyAcross(rng)
End Sub
Function copyAcross(rng As Range)
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("Budget")
targetRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 2
ws.Cells(targetRow, "A").Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
End Function
this gives two subs that the buttons can be pointed to. In each sub you can define the range you want and the function will copy it across.
Note: for this to work column A in the Budget file would need at least some value somewhere in it, the first copy would then be put two rows below that

How to automatically hide column based on row value, which is based on an if function from an opposing worksheet?

Please bear with me as I am self-taught and very new to VBA coding.
I need help with a code for a work project to automatically/dynamically hide a column based on a row value within that column. In my example, based on a Yes/No data validation list in an alternate worksheet, the current worksheet will update and return the same "Yes" or "No" value. If the answer is "No", I need that column to automatically disappear once the user has chosen that option from the Data validation list.
The data set is as follows:
The Yes/No result is on Row 3, in the column range B:AR.
The results of Row 3 are as a result of a transcode formula from another worksheet.
Bonus points if the coding is truly dynamic, in that was I to add rows above Row 3, the code would automatically move to Row 4.
I have scoured the google realms and most code either doesn't update or is strenuously slow. An example of several codes I have attempted are below:
Sub Hide_Columns_Containing_Value()
Dim c As Range
For Each c In Range("B3:AR3").Cells
If c.Value = "No" Then
c.EntireColumn.Hidden = True
End If
Next c
End Sub
Hope a little faster
Sub Hide_Columns_Containing_Value( _
ByVal msg As String, _
ByVal r As Range)
Dim c As Range
Set c = r.Find(msg)
If Not c Is Nothing Then
c.EntireColumn.Hidden = True
End If
End Sub
So this is what you need to Do:
First Define a Named Range in the worksheet for the Rows you want to check No in. Benefit of Named Range is it is Dynamic, so if you add another row before 3rd row, it will dynamically move the Named Range to 4th Row.
Like this:
After Making the named range add this Code to the Worksheet you are on:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("roww")) Is Nothing Then
For Each cel In Range("roww")
If cel.Value = "No" Then Columns(cel.Column).EntireColumn.Hidden = True
Next
End If
End Sub
-Second Code to be added below the First One.
Sub hdd()
For Each cel In Range("roww")
If cel.Value = "No" Then Columns(cel.Column).EntireColumn.Hidden = True
Next
End Sub
Make Sure code is on the Correct sheet to work:
This will be a complete Dynamic code.

[Excel][VBA] Look up value from another sheet and copy it's BG

I have been assigned simple task (at first I thought so), to monitor input into excel and if there is number (like 0000068145) I need to highlight it with it's colors. So I created two sheets Sheet1 and Database. In Database I keep my data like this:
So I used this code and it called whenever I change something :
Private Sub Worksheet_Change(ByVal Target As Range)
End Sub
And I thought about using Vlookup, but it will retrieve only value as far as I know.
So how would you realize this kind of operation?
I can't use Vlookup, and I really need "database" to be separate from main sheet.
Sorry for my english
I think your approach using Worksheet_Change is correct.
Put the following into the Sheet1 code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oCell As Range, oDBCell As Range
Dim dbWS As Worksheet
Dim lColor As Long
Set dbWS = ThisWorkbook.Worksheets("Database")
For Each oCell In Target
Set oDBCell = dbWS.Range("A:A").Find(what:=oCell.Value, LookIn:=xlValues, lookat:=xlWhole)
If Not oDBCell Is Nothing Then
lColor = oDBCell.Interior.Color
oCell.Interior.Color = lColor
End If
Next
End Sub
Your "Database" sheet must be named Database.
Now if you put some value into a cell in Sheet1 which is also in column A of your database sheet, then the color is copied from this database sheet.

Loop filters for all items in table column of excel

I'm trying to build a code that will filter a table by product type, of which there might be multiple items. I need the table to filter through each of the product types to build a hierarchy for each product family.
I'm thinking it should be something like:
Sub familyfilter()
With ActiveSheet.ListObjects(1)
For Each Item In .Columns(1)
.AutoFilter.ShowAllData
.Columns(1).autofilterrange.AutoFilter Field:=3, Criteria1:=Item
'[insert sub call here for hierarchy]
Next Item
End With
End Sub
I won't know the values in the family column, so I can't set a list of values to cycle through.
So if anyone knows how to do this for all the items in the column, I'd appreciate it!!
Thanks
Ah, I see what the issue is. Since you are doing For each Item in .Columns(1), it's only going to look in the COLUMN altogether. A quick test is this:
Sub test()
Dim cel as Range
for each cel in columns(1)
cel.select
next cel
end sub()
If you go through that line by line (using F8), you'll see it select the column once, loop then end.
The fix is to use a range, instead of a column:
Sub test()
Dim rng as range, cel as Range
Set rng = Range(Cells(1,1),cells([lastRow],1))
For each cel in rng
' Do whatever in the cell
Next cel
end if
end sub
For the last row, you have multiple options to get it. If your data is in one 'solid' table (i.e. no blanks in column 1 until you reach the end of your data), you can use this to get the last cell, lastCell = Cells(1,1).End(xldown).Row. Or, if you do have some gaps in Col. 1, lastCell = Cells(1048576,1).End(xlup).Row.
Edit: This should get you started - I'm not sure if the filter part will work in this loop, so you may need to put that outside of it, but let me know if the above helps.

Using VBA, how to populate ComboBox values based on specific comlumn in an excel table

Using VBA, I'm trying to build this sophisticated form to add new rows to an existing table.
I want to have this ComboBox that will list the values already exists in the one of the table's column.
I'm new to VBA. and I tried some Range/Selection and sort combinations with no lack so far...
Here's what you're looking for.. It should get you started, Just adapt the Sheets and Range to your needs.
Dim cmb as ComboBox
Dim rng as Range
Set cmb = Worksheets("Sheet1").ComboBox1
'To fill based on range
For Each rng in Worksheets("Sheet2").Range("C2:C300")
Cmb.AddItem Rng.Value
Next
'To fill from table where ListColumns(N) is the specific column
Set rng = Sheet2.ListObject(1).ListColumns(3).Range
For Each rng in rng
Cmb.AddItem Rng.Value
Next
Cmb.ListIndex = 0
*EDITED:*Chris is right, my original code had errors. Posted answer on way to work didn't have time to check. The code above works fine. Chris suggestion on just using .value to fill is quicker. I honestly didn't know you could do it like that.
you need to create your table column range,
Either you can insert your row in side the range
Or you need to first add row to table and resize your range
and pass that range pass to SetRng parameter,
userFormName is user form name,
ControlName is combobox name
Public Function FillRangeComboBox(userFormName As String, ControlName As String, SetRng As Range) As Boolean
Dim ObjFormName As Object: Set ObjFormName = ThisWorkbook.VBProject.VBComponents(userFormName)
Dim ObjControlName As MSForms.ComboBox: Set ObjControlName = ObjFormName.Designer.Controls(ControlName)
''set combobox value
With ObjControlName
.RowSource = SetRng.Address
End With
End Function

Resources