I have a long list of names in my "Main Sheet". I need to loop through these rows, create a sheet with the same name and then add a hyperlink to that sheet.
I was able to create the sheets, but I can't create the appropriate hyperlink to the matching sheet.
Here's a snippet of the code:
'HERE, I COUNT HOW MANY INDIDUAL ROWS THERE ARE IN COLUMN A'''
Sheets("MainSheet").Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Total = Selection.Count
'here, I copy the cell value and create a new sheet, using the cell value as the name
'Since some cells had more than 31 characters, I had to create a code to only take the first 30 characters
For i = Total To 1 Step -1
Sheets("MainSheet").Cells(i, 1).Select
Take = Left(ActiveCell, 30)
Sheets.Add.Name = Take
Worksheets("MainSheet").Activate
Worksheets("MainSheet").Cells(i, 1).Select
Next
The code works.
I now need to loop through the same list and create the appropriate hyperlink.
Here's an example of the rows:
Temperature Probe and Data Sensor A1
Temperature Probe and Data Sensor A2
Temperature Probe and Data Sensor A3
Temperature Probe and Data Sensor A4
Air and Pressure Sensor A1
All of these will have their own sheet, but I would want to click on the cell value to bring me directly to that sheet, without having to manually search through 200+ sheets. In short, the mainsheet will act like a directory to the rest of the Excel workbook.
To link in the same workbook, use a formula with this format, =HYPERLINK("[Workbook]Worksheet!A1", "Link Text"). For more info see Work with hyperlinks in Excel.
You can even make the formula find the workbook name, assuming the workbook name and file path don't include any square brackets. For more info see this page. The formula is =HYPERLINK(MID(CELL("filename"), FIND("[",CELL("filename")), (FIND("]",CELL("filename")))-FIND("[",CELL("filename"))+1) &A5 &"!A1", "Link Text"). Change the last part of that formula, where A5 is a cell with a worksheet name, A1 is the link's target, and Link Text is any text or a cell reference.
If you paste the formula with code, then use two quotation marks to paste one quotation mark in the formula, ActiveCell.Formula = "=HYPERLINK(MID(CELL(""filename""), FIND(""["",CELL(""filename"")), (FIND(""]"",CELL(""filename"")))-FIND(""["",CELL(""filename""))+1) &A5 &""!A1"", ""Link Text"")".
Or... Here's a post about how to add a table of contents to your workbook. Maybe you can just save and run a separate macro.
Related
I am looking for a Excel VBA code to select the resulting Form address on Sheet 2 from the set of States on Sheet 1, but I need to copy the cell and paste it to retain the existing hyperlink attached to Form.
The only common data is the States.
I used INDEX MATCH but it only gets the word "Link" without the hyperlink itself.
I couldn't actually Select the cell, then copy and paste it.
Sheet 1
Sheet 2
I tried but don't have any idea how. As long when I choose what's selected on Sheet2 State (e.g Sheet2 Cell D2 - Alabama), the corresponding Form Link (e.g Sheet1 Cell B3 - Link) will be selected and copied through the Macro.
Sub test2()
Dim link As Range
Set link = Range("INDEX(Sheet1!B:B,MATCH(Sheet2State,Sheet1State,0),0)))")
Set s1 = Range("D5")
link.Copy
s1.PasteSpecial
End Sub
I am very new to VBA but have a need use it in a report I run weekly. There are six columns that I need to copy and paste into another sheet each week - this would be cumulative so it would paste the new data after the old data each week, not replace it. The range for this case is A6:A24 through F6:F24. One additionally caveat is that I would like to add one column called date that posts that days date - is that doable? I have attached a snippet - my idea is to create the column headers in the new tab (manager, employee, etc.) and fill data down each week so I can create a chart with historical data.
Adding what I have come up with:
Sub sbCopyRangeToAnotherSheet()
'Method 1
Sheets("Summary Build").Range("A6:F24").Copy Destination:=Sheets("Sheet1").Range("A2")
End Sub
You were nearly there. Your code will copy to A2. To find the next blank cell you need to start at the bottom of the spreadsheet, go up to the first filled cell and then down one. Bottom of the spreadsheet is range(sheet.rows.count,1) To go up we use End(xlup) and then down one .offset(1,0) That's One row, no columns. Put it together and we get range(sheets("sheet1").rows.count,1).end(xlup).offset(1,0)
So your line is
Sheets("Summary Build").Range("A6:F24").Copy Destination:=range(sheets("sheet1").rows.count,1).end(xlup).offset(1,0)
To put today's date into a cell you can use the date function eg:
Range("A2") = Date()
EDIT: Sorry it should read
Sheets(1).Range("A6:F24").Copy _
Destination:=Sheets("sheet1").Cells(Sheets("sheet1").Rows.Count, 1).End(xlUp).Offset(1, 0)
I need to build a macro that allows me to copy a range of data to the clipboard but that data is stored in a daily changing number of rows. To clarify, I have two tabs on this blank worksheet that I fill out every day. Tab 1 is called "Recap", and based on what I type into the "Recap" tab I have data pulling into my second tab called "Exception Log" through "if" formulas. The data pulls into A8 through F8 and Column E is blank so that if I copy A8:F8 it matches the formatting in another spreadsheet where I will paste the data. Some days there are only 3 rows of data meaning I want A8:F10 copied into the clipboard but other days there is 30 rows of data meaning I want A8:F37 copied into the clipboard. In an attempt to try to make this a little easier I added a basic count formula to Cell H5 that counts the number of rows with data in them and therefore the number of rows that I want copied from columns A to F starting at row 8 but I can't figure out how to work it into a Macro. Any ideas? Thanks in advance!
Example : To copy from a range in sheet1 to another range in sheet2 starting at C6 :
Range("A8:F13").Select
Selection.Copy
Sheets("Feuil2").Range("C6").Select
ActiveSheet.Paste
if your row number is H5 :
n=range("H5").value
Range("A8:F" & n).Select
Selection.Copy
Sheets("Feuil2").Range("C6").Select
ActiveSheet.Paste
I have a macro that populates cells on a blank worksheet with values from another form worksheet using R1C1. The issue is that the position of the source data on the form worksheet changes as users add rows to input their data. The A1 solution to this would be to use a fix Cell column reference and allow the reference for the row to change 9ex. Cell=Sheet1!$A25, which could then change to Cell=Sheet1!$A26 as a row is added above. How can I make my FormulaR1C1 change in the same way as my A1?
Correct situation:
Cell A1=Sheet1!$F13
Therefore, ActiveCell.FormulaR1C1 = "=Sheet1!R[12]C6"
But when I add a row above F13:
Cell A1=Sheet1!$F14
But, ActiveCell.FormulaR1C1 = "=Sheet1!R[12]C6", Does not respond to the shift row down
I'm developing some excel macros, and now I'm stucked with following,
I want the macro getting the cells from another file and put it on the new one but it is important to consider that copy the full range is not an option, so for example first i Need to copy a1 then a2 , etc ...
the reason is because after each "paste" process, I have to check, the old value and then start a triger of another macro depending on both values, and if ai paste the full range at once it is not working,.
Try getting the Cells value at given row and column from the Worksheet objects you are manipulating.
Example : I want to copye the value (cell content only, not style) from worksheet1 cell A1 to worksheet2 cell B3.
worksheet2.Cells(3, 2).Value = worksheet1.Cells(1, 1).Value
Simple as that.