Make variable hyperlink from cell data - excel

Hi I am kind of new to VBA and i can't seem to find what i am looking for.
What i want to make is a macro that links to another page in my workbook that refers to data in a certain cell.
from certain datapoints i have a cell set up that as everything is filled in it gives the name of the page i want to link to (lets say "overview_Oct_2020" by filling in the month and year in other cells), and when running the macro go to that.
I seem to totally blank on how to do it. I made a =HYPERLINK() version pretty easily, but i want to change that to a button, hence the reason for a macro.
so technically i want to make a button with a macro that goes to [TEXT IN CEL A1]!A1

Put this macro in a standard module and assign it to a button on the worksheet
Sub link()
Dim textInCelA1 as String
textInCelA1 = Range("A1").value
Sheets(textInCelA1).Activate
Range("A1").Select
End Sub

Related

How do I copy a range including hidden cells(by filter)?

I know basically the same questions has previosly been asked and answered on many forums, including stack overflow, but none of the answers satisfy my requirements.
I want to press a button, which will copy a range of around 100 cells. I then want to press a different button, in a totally different workbook (which is in no way connected to the first workbook) and that will paste my copied range.
The issue is that I have a filter in my workbook, which will hide some of the cells in the range. These are not being copied but I need to copy the full range. (The reason I want to copy the full range is because the values need to align when I paste it)
My issue with all other given solutions are:
One solution is to remove the filter when I copy the range. This is not something I want to do as I don't know a way to restore the filter. If this is done before I paste the values, the copied range will "exit?" (it will no longer be copied). And due to the files not being connected, I can't perform any actions with the paste button.
Using a loop to copy the range as a array(Variant), This doesn't work since I can't "transfer" that variant to another workbook which is not connected. Or at least I don't know how to do that.
Is there any other method I can use?
It is a bit of a hack, but because both workbooks have access to the set of custom lists defined for Excel, you could create a custom list with the information needed to identify the source range from the target workbook. The code for the copy button would record the range address, sheet name, and workbook name of the selected range as follows:
Sub copy_range_info()
Application.AddCustomList Array("DeleteMe", Selection.Address, Selection.Parent.Name, Selection.Parent.Parent.Name)
End Sub
On the destination worksheet, the code to paste data would look like this:
Sub paste_range_from_other_workbook()
Dim last_list As Variant
last_list = Application.GetCustomListContents(Application.CustomListCount)
If last_list(1) = "DeleteMe" Then
Workbooks(last_list(4)).Worksheets(last_list(3)).Range(last_list(2)).Copy
ActiveCell.PasteSpecial xlPasteValues
Application.DeleteCustomList Application.CustomListCount
Else
MsgBox "You need to copy a range first using that special button"
End If
End Sub
Because this creates a custom list in Excel that will be permanent, I'm deleting it just before the "else" in the code above. It might be advisable to scan the custom list and delete any lists that begin with "DeleteMe" so if someone does a copy without a corresponding paste, it won't result in more than one custom list of this type.

Need to paste Input on multiple sheets Excel, vba

Problem with referencing back to sheet2I have a workbook with 37 sheets. Each sheet requires the user's name.
I have a inputbox for them to put in their name, however it only posts on the active sheet. I have tried referencing back to the cell it fills from the macro but it wont reference.
Here is the code
Sub Name()
Set wsDst = ThisWorkbook.ActiveSheet
Sheets(2).Range("B16").Value = inputbox("Please type your first name and last intial.", "Name")
End Sub
Now if I go to Sheet3 and try ='Sheet2!B16
that is exactly what shows in cell B16.
The main issue is that the user's name will not always be in B16
Sheet4 is B18.
I know this is probably an easy fix for most, however I am still learning all the syntax's and honestly have used codes others have posted and been able to edit them to my needs.

Need to copy cell to another sheet and then overwrite with new value (loop)

I need to make a VBA which copy a cell into a cell in another sheet. (Same workbook).
Afterwards i have to create a pdf (i have VBA for this).
After the pdf creation, i need do this all over automatically and i would like to have a VBA for this. Because i need to make 200 pdfs
My question is therefore:
How can i create a VBA which copy a cell from a list i sheetB to a cell in SheetA, and after the creation of the pdf, do it all over with the next cellvalue from sheetB? I guess it is something with the "looping" tool?
A good way to create basic VBA to automate standard tasks it to record a macro while you perform the steps. Afterwards, you can view the VBA that was generated for the macro, automate it further as necessary. Here's some instruction and examples:
Getting Started with VBA in Excel 2010
Recording a Macro to Generate Code
Revising Recorded Visual Basic Macros
I'm not aware of a "looping tool" but there are various ways to loop through data with Excel.
Edit:
Looping through a list is the easy part. For example, the following code pops up a MsgBox with the value of each cell in range A1 to A15:
Dim cel As Range
For Each cel In Sheets("Sheet1").Range("A1:A15")
MsgBox cel.Value
Next cel
Get your VBA together for doing your task once, add the code to your question, and then we can stick the loop in the correct spot.

Create copy of excell sheet with code problems.

Created a sheet in excel in which when new information is needed I will simply create a copy of the worksheet into a new tab. However I have a code that allows me to clear certain cells or erase them to enter the data, it goes as:
Sub Clear_Cells()
Range("B5").ClearContents
Range("C5").ClearContents
Range("D5").ClearContents
Range("E5").ClearContents
Range("F5").ClearContents
Range("B8").ClearContents
Range("C8").ClearContents
Range("E8").ClearContents
Range("C9").ClearContents
Range("C13").ClearContents
Range("C14").ClearContents
Range("D13").ClearContents
Range("D14").ClearContents
Range("E15").ClearContents
Range("B18").ClearContents
Range("C18").ClearContents
Range("D18").ClearContents
Range("E18").ClearContents
Range("F18").ClearContents
End Sub
The problem is when I create a new page and try to clear the cells in that page it always clears the cells of the original page. I know it has to be something simple but just cannot put finger on it.

Linking cells to each other; having cells update linked cells and vice versa

I have two ideas that could lead to more or less the same result.
I am trying to have similar cells or tables update themselves to whatever the most recent entry was in the linked system. For example, cell A1 is linked to cell B2 (in this system that I am trying to create). I would enter something like "1" or "Text" or whatever in A1 and the system would update cell B2 to whatever I entered in cell A1. However the opposite must work in the same manner. If I changed whatever in cell B2 to, say, "5", cell A1 would also display "5". Also, note that I have Excel 2013.
I need this to work with a cell or a table. So, getting to the possible solutions...
A subroutine in VBA that automatically updates all the linked cells or tables.
Some sort of mechanic unknown to me that uses VBA or another Excel aspect to do this, like a function or tool.
In your answer or solution, please be mindful to my inexperience with VBA. Thanks in advance.
You can try a worksheet change function:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address then
ActiveSheet.Range("B1").Value = ActiveSheet.Range("A1").Value
ElseIf Target.Address = Range("B1").Address then
ActiveSheet.Range("A1").Value = ActiveSheet.Range("B1").Value
End If
End Sub
Although this seems like it might create an infinite loop (the update from the change causes another change) it DOES work for me in Excel 2010..
There are other Worksheet functions you can try as well (e.g. Worksheet_SelectionChange)
This macro needs to be placed/entered as a WORKSHEET macro on the sheet where you desire to use it..it will not work in a Module.
To install:
1) Save your workbook as a macro-enabled file.
2) Close Excel, reopen file, and enable macro security
3) Type Alt-F11
4) In the project explorer view on the left, look for your sheet name. Double click it
5) In the code entry area on right (big window) paste the example code above
6) Return to your worksheet and try it.

Resources