How to create hyperlinks in VBA for mutiple cells? - vba

I have to create hyperlinks for a list of variables to get easily to the datas in a database. My database contains summary of many variables coming from different sources. My problem is, I have to skip multiple rows fill with duplicates and blank cells. The number of rows to skip depends for every variable. I also want that my hyperlinks have the name of the variable from the database (example : Customer_Since). Is there a way to create a loop to skip the good number of rows and create a hyperlink? Example : if I click on the link named Customer_Since, it takes me to the row that contains the summary of the variable Customer_Since. Can somebody help me?

To create a hyperlink you can use this code:
ThisWorkbook.Sheets("SheetName").Hyperlinks.Add Anchor:=Range("A10"), Address:="", SubAddress:="Sheet2!B5", TextToDisplay:="Link"
where:
Anchor - cell, where there will be a hyperlink;
SubAddress - range to navigate to;
TextToDisplay - text in the link.
You can use another vba code with your rules to correctly insert Anchor`s range.
Or please provide more information and examples of the input and output data to get help.

Related

Excel table does not expand automatically when data added by vba includes a hyperlink

I have several excel workbooks that I want to consolidate in one excel table using the GetValue = ExecuteExcel4Macro(arg) method.
When data is added by the macro to the bottom of the table, the table should expand automatically and transfer formulas and formats.
This works pretty well up to the point where I want to add a hyperlink:
ActiveSheet.Hyperlinks.Add anchor:=ActiveWorkbook.Worksheets("Series").Cells(Irow, 3), _
Address:=fullpath, TextToDisplay:=GetValue(pfad, datei, blatt, "F3")
When including this line, the hyperlink is correctly entered, but the table will not expand. Without the hyperlink the table expands as supposed to.
Can anyone support here?
Thanks!
Use this code a line, before yours code :
ActiveWorkbook.Worksheets("Series").Cells(Irow - 1, 3).ListObject.ListRows.Add AlwaysInsert:=True

Referencing a sheet by index number

I've got a LibreOffice Calc spreadsheet that I use to keep track of my accounts receivable at work. Each sheet lists invoices and their status (paid, unpaid, etc) as well as info about each invoice. I'm trying to create a Summary sheet that lists certain data from each sheet. Creating the sheet manually is easy, but I'm trying to "automate" the process. I want the summary page to auto-update if I add a new sheet (or remove one) as I add and remove accounts to the file.
I know that LibreOffice assigns each sheet an index number that I could refer to in some sort of formula, but I cannot find a function that I can use to refer to that index number when getting a value from a cell within it. One would expect that a function like Sheet(2) would reference the second sheet, but, alas, that is not so!
I've tried using the indirect and address functions without success, but I'm not sure if I'm not understanding these functions or if they're not appropriate for what I'm trying to accomplish.
This has been a missing piece in Calc for a long time. The preferred solution is to write a user-defined function. Spreadsheet formulas do not access sheets by index number but Basic can.
The following function is from https://ask.libreoffice.org/en/question/16604/how-do-i-access-the-current-sheet-name-in-formula-to-use-in-indirect/.
Function SheetName(Optional nSheet)
If IsMissing(nSheet) Then
SheetName = ThisComponent.getCurrentController().getActiveSheet().getName()
Else
SheetName = ThisComponent.getSheets().getByIndex(nSheet-1).getName()
EndIf
End Function
Then get a relative address of the first sheet cell A1 like this.
=ADDRESS(1,1,4,,SHEETNAME(1))
A slightly different function is given at https://forum.openoffice.org/en/forum/viewtopic.php?f=9&t=49799.

Excel VBA - Pull information into user form to update

I am trying to create a userform that allows the users to update issues stored in a specific sheet (called Issues List). I have built a dropdown list using data validation that allows the user to select the unique issue name from a list. I have created a button next to that dropdown which opens up the userform and correctly imports the issue name identified from the dropdown.
What I need to figure out is, when the user form is initiated how do I have it search column B in my Issues List sheet and identify which row contains the issue selected by the user, and populate the fields of the user form with the information found in rows C-X of the Issues List sheet.
What I have been trying to use is an index match function, but have been unsuccessful in getting the code to work. An example of what I have been using is:
Resolved.Value = Application.WorksheetFunction.index
('Issue List'!$X$2:$X$1000,Application.WorksheetFunction.match
('Priority Table'!I35,'Issue List'!$B$2:$B$1000,0))
Any help would be greatly appreciated.
Thanks in advance!
When you use Worksheet Functions in VBA, you still have to pass in the ranges using VBA language:
So instead of:
'Issue List'!$X$2:$X$1000
you would use:
Worksheets("Issue List").Range("X2:X1000")
And instead of:
'Priority Table'!I35
Just use:
Worksheets("Priority Table").Range("I35")
Note that you can also refer to ranges by names, which can make coding easier and also far safer. When you insert rows in spreadsheets, Excel doesn't automatically update ranges in any VBA code. A reference to I35 will always to be I35.
Instead, define a name for cell I35 in Excel as normal, then refer to it in the code.
For example, if you name I35 as "Issue"
You can refer to the cell by:
Range("Issue")
(If it is a global variable, which it is be default as long as it's a unique name in the workbook, you don't need to use the Sheets("Priority Table") qualifier.
Refer to this documentation for more info on how to refer to ranges in Excel from VBA:
https://msdn.microsoft.com/en-us/library/office/gg192736(v=office.14).aspx

Excel VBA; Search rows grabbing values and pasting them into another worksheet

I have two workbooks;
(WB1) with two sheets; "Input" and "Output"
and
(MacroWB) with the macro and a "Column Header" list.
Example file: "Messy" sheet = input, "Organized" = output
https://drive.google.com/file/d/0B-leh2Ii2uh9bDBFbDBHbGcxbUU/view?usp=sharing
I need help coding a macro to do the following:
1) Create a loop to go through each row of the "Input" sheet searching for values matching cells in the "Column Header" list.
2) When a matching value is found; take the data from the cell immediately to it's right (in the "Input" sheet) and paste it into the corresponding column of the "Output" worksheet.
3) Once every "Column Header" item has been searched/pasted for that row; move to the next row of the "Input" sheet. Rinse and repeat until all rows of the "Input" sheet have been searched/pasted.
Here is an example, the letters are to be column headers and the numbers are to be copied to the appropriate "Output" sheet column.
https://drive.google.com/file/d/0B-leh2Ii2uh9TXRGTnFDRU1jY0U/view?usp=sharing
Keep in mind that the actual data file has ~50 columns and ~3000 rows.
Also that the data is not all Letter/Numbers like the table above, it is more like the data in the linked .xlsx file.
If there is anything I haven't been clear about, please ask and I will try my best to clarify. Also I may be WAY over thinking this, if so.. please let me know.
THANK YOU ANYONE THAT CAN GET ME GOING IN THE CORRECT DIRECTION!!!
-Joe
Skip the the VBA and use Text to Columns the Data tab. I'malways copying html and its works 99% of the time. If the html is pretty and properly formated you may get away with using the fixed width option, otherwise gor for the delimted and choose "tab". If tab doesn't work try using spaces, assuming that your cells don't contain spaces.
The other option that I've had work on rare occasions that text to columns doesn't is simply saving the text in word and saving as rtf and then opening that in notepad++ (which everyone should have.) Copy from ++ to excel and that usually fixes the problem.
EDIT: If you right click before pasting and click "paste special" this regularly helps with html pasting.
In your sample file, I used the following formula in A2 of Organized sheet (assumed 50 as max columns in Messy):
=IFERROR(OFFSET(Messy!A1,0,MATCH(Organized!A$1,OFFSET(Messy!A1,0,0,1,50), )),"")
Dragging it to H11 produced the following result:
The sample data is not complete, and some 'tags' in Messy sheet are not consistent (SiteID vs SITE_ID), but it should help you get started.

Find and Replace a lot of abbreviated text with expanded form and other text

I have multiple lists of items in Excel that are in an abbreviated form and I want to set up a macro that will automatically go through the list and replace their abbreviated form with a regular name that also includes characters so I can just run a delineated Text to Columns function in Excel that will allow me to view and sort them properly. For example:
It1
It2
It3
It4
to
Red*Category 1*Item One
Red*Category 2*Item Two
Blue*Category 1*Item Three
Green*Category 2*Item Four
All I need is a simple find and replace for each individual item and I know that I will have to create that from scratch, but each list will have the same items/categories so I don't know the best way to go about it. I am wondering if I should make one long macro in Excel listing each individual find/replace or if it's possible to do something like create an XML file with a
<find>It1</find>
<replace>Red*Category 1*Item One</replace>
and just have a macro that references it? My goal is to build one file then have a macro I can use on each list.
For the moment assuming colours are determined by font, and and using the approach here then with a lookup table as shown the results for the sample data can be achieved with the following formula (copied down to suit):
=VLOOKUP(B1,$K$1:$M$23,2,0)&"*Category "&RIGHT(A1,1)&"*Item "&VLOOKUP(VALUE(RIGHT(A1,1)),$K$1:$M$23,3,0)