Change batch of hyperlinks automatically - excel

I tried to change many hyperlinks, which are located in specific cells. For example in F21:F30 the hyperlinks are located. F21 contains the correct hyperlink with the folder path ending in ..\m%20(70). The cell G21 contains the text "70 General". Now G22 contains the text "71 Electric installation". Thus I want the hyperlink of F22 to end with ..\m%20(71). Now G23 contains the text "73 Phone installation", so naturally I wan the hyperlink of F23 to end with ..\m%20(73). In conclusion there is a sequence in column G which is part of the hyperlink path in column F.
The above example also applies to H21:H30 and I21:I30 and to F34:F43 and G34:G43 and many more cells in the same sheet (see picture).
How can I change all of the hyperlinks automatically?
The function
=HYPERLINK
is I think not an option, because the number is in the same cell as the text.
I also tried to include this solution Use VBA to hyperlink based on cell text

What you can do is use the function Hyperlink
if the F column write:
=HYPERLINK("..\m%20(" & LEFT(G21,INSTR(G21, " ") - 1) & ")")
So we look for the first space, get all chars before that and use this in the HYPERLINK

Related

Excel Formula to display text based on value of two cells

Im looking for a way to display text of a cell based on the below two conditions :
If Cell C20 contains certain words like "ghan", "ERC", "VSL" AND cell D22 is <> "-" then cell i22 should display the content of cell C20.
If cell C20 does not contain any of these words regardless whether D22 is ="-" or contains a number it should remain as "-"
Screenshot attached
Here's what i have tried so far :
1) =IF(AND(ISNUMBER(Aug!I555),ISNUMBER(SEARCH("ERC",Aug!B555))),Aug!B555,"-")
2) =IF(ISNUMBER(Aug!I596),Aug!B596,IF(ISNUMBER(SEARCH("*ERC*",Aug!B596)),Aug!B596,"-"))
This is what im using for now as a temporary solution
3) =IF(D22<>"-",IF(ISNUMBER(SEARCH("ghantoot",C20)),C20,IF(ISNUMBER(SEARCH("sand",C20)),C20,IF(ISNUMBER(SEARCH("vsl",C20)),C20,IF(ISNUMBER(SEARCH("wet",C20)),C20,"-")))))
In I22:
=IF(ISNUMBER(D22),
IF(OR(ISNUMBER(SEARCH("ghan",C20)),
ISNUMBER(SEARCH("ERC",C20)),
ISNUMBER(SEARCH("VSL",C20))),
C20,
"-"),
IF(D22="-","-","d22 not number & not -"))
I don't think you stated what happens with all branches of the logic, so I have put placeholder text there for you to fill in yourself. This is:
"d22 not number & not -"

Is there a VBA code that check and moves values from A column to the beginning of B column?

I found a lot of formulas on the Internet which copies "n characters" but they did not provide a solution for me. I am searching for a VBA code which is able to move the specific value from a column to the beginning of adjacent column. For example, the VBA code will check the A column for the word "Warm" and "Cold", and if they are available, it will move them as shown in the example. Thank you in advance for your help.
Example
Edit ( Solution by #Dominique ): =IF(A1<>"";IF(RIGHT(A1;4)="Warm";"Warm "&B1;B1))
You can't move a part of one cell to another. This is what you need to do:
Search for " Warm" (or " Cold") in a cell in column A and replace " Warm" (or " Cold") by an empty string within that cell.
Take the cell, next to that (use the Offset() function) and add the word "Warm " (or "Cold ") at the beginning of that cell.
Do this for the entire A column.

Converting HYPERLINK() - to text with an underlying link

Suppose I have a column with many (hundreds) of rows, each with a HYPERLINK formula, e.g.
=HYPERLINK("https://npiregistry.cms.hhs.gov/registry/provider-view/99999", "99999")
How can I convert all into a cells that contain the text - but with an underlying link (as in with CTRL-K), e.g., 99999
Thanks!
After further investigation, the problem is not the security setting of the Excel for Mac but the hyperlink formula was composed with 2 cell references; the display text, and the link.
The VBA function to insert / replace a hyperlinked to a cell is as of the following.
ActiveSheet.Hyperlinks.Add Anchor:=current_range, Address:=address_string, TextToDisplay:=display_string
In your situation, you have to replace current_range, address_string, and display_string in the VBA syntax.
In my above example, since we are using a For loop to loop through all the cells in selection, you can leave it as current_range.
For the address_string, and display_string, you will feed the function with the cell location of those two on your spreadhseet. Since your spreadsheet has the address string stored in two separate columns, you want to reference to the column by either using the familiar cell reference format, Range("$C" & current_range.row) format, or use the offset method, which involve in counting the index of the column. Example, current_range.offset(0, -10).value. The -10 in the offset is how many column you want to move left from your current_range.
Note, it is important to add the .value at the back of your cell reference so it's getting the data (String) stored in the cell instead of the potential formula in the cell.
Create this macro.
Sub convert_hyperlink_formula_to_hyperlink_cell()
Dim address_string As String, display_string As String
Dim current_range As Range
For Each current_range In Selection
address_string = Mid(current_range.Formula, 13, InStr(1, current_range.Formula, ",") - 14)
display_string = current_range.value
ActiveSheet.Hyperlinks.Add Anchor:=current_range, Address:=address_string, TextToDisplay:=display_string
Next current_range
End Sub
Select the range of your Hyperlink formulas then run the macro. That should convert the hyperlink formulas to actual hyperlinked cells.
Please try this sample file.
Convert Hyperlink Sample File.xlsm
I have made a copy of your posted formula, and pasted a few lines in the sample file. The macro is already setup in the Excel file for your to test.

How to pull keywords from an excel cell

I work in sourcing and I'm trying to look through a list of cells that contain part numbers and their description, but only pull the part number from the cell and place it in another column.
The part numbers have one of 10 possible prefixes (i.e. ABC, DDA, GHF, AH, etc.). The cells may look something like this:
Tire Pressure ABC123873 Monitor
Oil Life ABC849999999021 gauge
Air conditioner GHF211 maintenance
And I want to be able to search that entire list and only pull the following information into another column:
ABC123873
ABC849999999021
GHF211
As you can see from above, the challenge is that the part numbers are all different lengths and have no particular convention to them. The only thing you know about them is that they can have one of ten possible prefixes as I mentioned above (ABC, GHF, etc.).
The current solution I have looks something like this:
C2=FIND("ABC", A2)
D2=FIND(" ", A2, C2)
E2=MID(A2, C2, D2)
Where cell A2 contains the complete part number and description, C2 finds the beginning location of the part number by searching for its prefix, D2 finds the ending location of the part number by searching for a space, and then E2 pulls the substring between those two locations.
As you can see, this isn't a very robust solution and it only allows me to search for parts that start with ABC. I want to be able to search for all 10 possible prefixes (ABC, DDA, GHF, AH, etc.) but that does not work. I tried the approach below:
C2=FIND({"ABC", "DDA", "GHF", "AH"}, A2)
But that only searches for the ABC parts and disregards the other prefixes. Any help you all can offer will be greatly appreciated!!
This is how I would do it. I created a list of prefixes to search in column G. You could even put them on a separate page to keep it cleaner.
=MID(A1,FIND(G1:G2,A1,1),FIND(" ", A1, FIND(G1:G2, A1, 1))-FIND(G1:G2,A1,1))
I only tested two prefixes but just change G1:G2 to G1:G10 and put all you prefixes in them. The formula looks in A1. The first FIND finds the beginning character number. The rest of the equation is calculating the end of the product number minus the beginning which returns the amount of characters to return. Its important to know that MID isn't wanting the beginning and end character. It wants the beginning character and the number of characters after that to return. So FIND(" ", FIND(G1:G2, A1, 1)) does not work as it returns too many characters. Give it a try.
Oh and don't forget to do Ctrl+Shift+Enter to enter the array formula
The VBA answer would be
Sub findProductCode()
' Variable Declarations
Dim productName As String
Dim productArray() As String
Dim wordCount As Integer
' Sets the active sheet to use
' Change Sheet1 to the name of your sheet
With Sheets("Sheet1")
' Selects the first cell to check
' Change A1 to the first cell with data
Range("A1").Select
' Loops through all rows until an empty row
' It will end if you have any empty rows in the midle of data
Do Until IsEmpty(ActiveCell)
' Reads text out of the cell
'Change A to the proper column
productName = Range("A" & ActiveCell.Row).Text
' Splits the string into individual words
productArray = Split(productName, " ")
' Loops through array to find the product number
For wordCount = LBound(productArray) To UBound(productArray)
' Check if the word has the desired 10 prefixes
' Add more Or Left(productArray(wordCount), 3) = "xxx" until you have 10 of your prefixes you need
If Left(productArray(wordCount), 3) = "ABC" Or Left(productArray(wordCount), 3) = "GHF" Then
' Sends the product number to its cell
' Change B to the correct destination Cell
Range("B" & ActiveCell.Row).Value = productArray(wordCount)
End If
Next
' Increments the active cell to the next cell down
ActiveCell.Offset(1, 0).Select
Loop
End With
End Sub
If you don't know how, you need to enable the developer tab in excel. File->Options->Customize Ribbon Add the Developer to the Ribbon. The save your worksheet as .xlsm It is the macro enabled workbook. Then go to the developer tab, Choose "Visual Basic" and double click "ThisWorkBook". Paste the code in. You can run the code from there for a one time deal or you can create a button on the sheet that you can run this macro whenever you want.
To add a button, go back to the sheet you want the button on. On the developer tab select Insert and choose the first form control Button. Draw the button on your sheet and a dialog box will appear. select the findProductCode macro and select OK. Now every time you click the button it will run the macro.
This isn't the prettiest formula, but it should get you on your way. There's definitely a VBA solution, if you're interested in a macro instead of a formula.
Assuming your Tire Pressure ABC123873 Monitor is in A1, enter this into B1:
=MID(SUBSTITUTE(SUBSTITUTE(A1," ",";",1)," ","-",1),SEARCH("ABC",SUBSTITUTE(SUBSTITUTE(A1," ",";",1)," ","-",1)),SEARCH(" ",SUBSTITUTE(SUBSTITUTE(A1," ",";",1)," ","-",1))-SEARCH("ABC",SUBSTITUTE(SUBSTITUTE(A1," ",";",1)," ","-",1)))
How it works, is it takes your A1, and first uses Substitute. I substitute the first and second [space] for ; and -. (Note, if there are more spaces than two, this will run into issues). Then, I just use Mid to extract the part of the cell starting with ABC and going until it hits the space. If you don't have "ABC" starting the values you want, you need to adjust the Search("ABC"... part (or use an array there). I am still working on it, but hopefully this helps give an idea.

Add common prefix to all cells in Excel

I have a column with some text in each cell.
I want to add some text, for example "X", at the start of all cells. For example:
A B
----- >>>> ----
1 X1
2 X2
3 X3
What is the easiest way to do this?
Type this in cell B1, and copy down...
="X"&A1
This would also work:
=CONCATENATE("X",A1)
And here's one of many ways to do this in VBA (Disclaimer: I don't code in VBA very often!):
Sub AddX()
Dim i As Long
With ActiveSheet
For i = 1 To .Range("A65536").End(xlUp).Row Step 1
.Cells(i, 2).Value = "X" & Trim(Str(.Cells(i, 1).Value))
Next i
End With
End Sub
Select the cell you want to be like this,
Go To Cell Properties (or CTRL 1)
under Number tab
in custom
enter
"X"#
Select the cell you want to be like this, go to cell properties (or CTRL 1) under Number tab in custom enter "X"#
Put a space between " and # if needed
Select the cell you want,
Go To Format Cells (or CTRL+1),
Select the "custom" Tab, enter your required format like : "X"#
use a space if needed.
for example, I needed to insert the word "Hours" beside my numbers and used this format : # "hours"
Enter the function of = CONCATENATE("X",A1) in one cell other than A say D
Click the Cell D1, and drag the fill handle across the range that you want to fill.All the cells should have been added the specific prefix text.
You can see the changes made to the repective cells.
Option 1:
select the cell(s), under formatting/number/custom formatting, type in
"BOB" General
now you have a prefix "BOB" next to numbers, dates, booleans, but not next to TEXTs
Option2:
As before, but use the following format
_ "BOB" #_
now you have a prefix BOB, this works even if the cell contained text
Cheers, Sudhi
Michael.. if its just for formatting then you can format the cell to append any value.
Just right click and select Format Cell on the context menu, select custom and then specify type as you wish... for above example it would be X0. Here 'X' is the prefix and 0 is the numeric after.
Hope this helps..
Cheers...
Go to Format Cells - Custom. Type the required format into the list first. To prefix "0" before the text characters in an Excel column, use the Format 0####. Remember, use the character "#" equal to the maximum number of digits in a cell of that column. For e.g., if there are 4 cells in a column with the entries - 123, 333, 5665, 7 - use the formula 0####. Reason - A single # refers to reference of just one digit.
Another way to do this:
Put your prefix in one column say column A in excel
Put the values to which you want to add prefix in another column say column B in excel
In Column C, use this formula;
"C1=A1&B1"
Copy all the values in column C and paste it again in the same selection but as values only.
Type a value in one cell (EX:B4 CELL). For temporary use this formula in other cell (once done delete it). =CONCAT(XY,B4) . click and drag till the value you need. Copy the whole column and right click paste only values (second option).
I tried and it's working as expected.

Resources