Excel Hyperlink - jump to cell and scroll window - excel

I am working in excel and I want to make a Hyper Link from the top of the page to another location on the page.
I type in a box at the top, and then right link and go down to hyper link in the dropdown menu I click it and select the tab that says "In This Work Book" and change it to where I want it to go. So all this is good and all but my Question is:
Can I make a Hyper link to bring me to a cell and scroll the window so the selected cell is the first row, instead of being near the bottom of the window?
Example:
Hyper link: "Test" Located in Cell A,1
Location Of Hyper Link: A,210
Now instead of having it put A,210 at the very Bottom and show the cells above it, I want to to be at the top and show the cells below it.
Thanks for the help,

Add the following VBA code to your worksheet:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
ActiveWindow.ScrollRow = ActiveCell.Row
End Sub
By magic, when you click a link, that cell will be at the top. If you don't want this behavior for all links, you can test the Target address.
You will have to save the code as a xlsm file so that macros are enabled. Use Alt-F-11 to open the VBA editor so you can actually add the code (double click the worksheet in the left hand pane, then paste the above code in the window that opens).

Related

Excel Hyperlink- When clicked make target cell always upper left hand corner

I have a very wide excel spreadsheet. It's formatted in such a way that there is specific data on each screen page. I have the first column frozen so I can place hyperlink buttons vertically. These buttons are hyperlinked to each of the formatted pages in the worksheet.
When I click one of the hyperlink buttons I would like the worksheet to scroll so the target cell in the UPPER LEFT corner of the screen.
I have googled and found this VBA code to place in the "thisworkbook" section of the VBA editor.
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
ActiveWindow.ScrollRow = ActiveCell.Row
ActiveWindow.ScrollColumn = ActiveCell.Column
End Sub
This code does not seem to work for me. If I'm at the far left of the screen and press the hyperlink button it scrolls to the target cell until it gets on the active screen. So basically it always ends up somewhere on the Upper right of the screen. However, if I click the hyperlink buttons the require the page to scroll to the left side of the worksheet it does work.
How can I make it so the target cell is ALWAYS in the upper left of screen after I press the hyperlink button?
Also, how do I know the above code is even running? The hyperlinks seem to be doing the same thing with or without it. I just cut and pasted the code into the VBA editor (per google) for thisworkbook. Is that it or do I need to check something so it will be activated?
Thanks in adavance.
There's a way to do that without using VBA. You can just use a normal hyperlink in the spreadsheet, and link it to "Place in This Document". Make sure you pick the correct Sheet and Type the cell reference that you want to go to (I assume this is A1). This will make sure that whenever you click that particular link, it will always go to that particular spot.
Here's how the edit hyperlink would look in an empty spreadsheet.

I want to create an add button

I am newbie in excel and I really need a button that if pressed adds a certain value to the cells I selected, is that possible?
You can add buttons to Excel by enabling developer mode:
On the File tab, go to Options > Customize Ribbon.
Under Customize the Ribbon and under Main Tabs, select the Developer check box.
Then on the developer ribbon you can click insert, then select a button to draw onto the sheet.
You will then be given the option to assign a macro to the button (Also later accessible by right clicking the button).
As for the VBA code of the macro, you would need to be more specific about what functionality you require, is the 'certain value' to be added to the selected cells always the same value?
Someone answered me in two minutes on another site with this perfect code for what I wanted, thanks a lot sir. It works like magic.
Sub Add_to_Selection()
If Not IsNumeric([E4]) Then
Exit Sub
Else
Dim cell As Range
For Each cell In Selection
cell.Value = cell.Value + [E4].Value
Next cell
End If
End Sub

Increment a cell by a value in another cell, each click on button or check box

I need to increment the value in a cell by the set value in some other cell, each time I click a macro button, or alternately clicking a check box.
I tried various formulas but they always return a circular error.
I looked at multiple replacement/increment macros but none do what I need or worked as described.
I'm good at formulas, but my VBA skills are very rudimentary at best.
Put an ActiveX button on the worksheet with Developer ► Insert ► ActiveX Controls ► Command button. Right click the button and choose View Code. Modify the code to the following:
Private Sub CommandButton1_Click()
[a1] = [a1] + [a2]
End Sub
Tap [Alt]+Q to return to your worksheet. Turn off Developer ► Design Mode. Every time you click the button, the value of A2 will be added to A1.

Is there a Macro to hide all sheets in a workbook when a certain cell is equal to 100%?

I understand the logic behind this but I'm unsure how to right the macro. I import up to 63 sheets of data into excel.
ALL of the sheets have a status in Column B Row 9. I would like to make a macro to hide all sheets in the workbook when B9 = 100%
If Worksheet.Column.B, Row.9= 100%
Worksheet.hide
Open the VB Editor ALT+F11. Under Microsoft Excel Objects right click Insert --> Module. Paste in the following code.
Option Explicit
Public Sub HideSheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Range("B9").Value = 1 Then
ws.Visible = xlSheetHidden
End If
Next ws
End Sub
The Option Explicit setting forces you to declare variables. I include this because, on top of good coding practice, it has saved me hours of debugging only to find I spelled a variable name wrong (such errors are captured before the code begins when adding this line).
The basic principle is that the code uses a For..Each loop to iterate through each worksheet in the workbook. IF cell B9 is 1 (corresponding to 100%) then the worksheet's Visible property is set to xlSheetHidden which hides the sheet. Sheets with this visible property can be unhidden if the user right-clicks along the worksheet tabs and selects Unhide.... If you don't want users to be able to unhide the sheets, you can set it to xlSheetVeryHidden which hides the sheet and disabled unhiding the sheet from the UI.
To run this macro you can click anywhere inside the code and click the button that looks like play (this is the Run Sub/Userform button) or you can press F5.
I would recommend setting the macro to a keyboard shortcut, or if you prefer to a button located somewhere on the worksheet.
To assign the macro a keyboard shortcut:
Under the Developer tab select Macros (or simply press ALT+F8) to display the Macro window
Under Macro name: select the name of your macro (HideSheets in this example)
Click Options...
Put the key in that you want to press to run the macro (in this case I chose CTRL+h for hide)
Select OK
Test by pressing the keyboard combination you specified
Additionally, you can assign a macro to run when a button on the worksheet is clicked, to do this:
Under Developer go to the Insert dropdown
Under ActiveX controls, select the command button
Draw the button anywhere on the page
Right click the button --> CommandButton Object --> Edit
Change the button text to whatever you want (like Hide Sheets for example)
Double click the button to open the code, you should see a Sub entitled CommandButton1_Click()
Type HideSheets into the subroutine like this (or whatever the name of your subroutine is)
Private Sub CommandButton1_Click()
HideSheets
End Sub
Exit design mode by clicking Design Mode under the Developer tab
Click the button to ensure the macro functions
Building on the answer from Soulfire, you can run the automatically anytime the value in the cell changes value. Just put the following code under the worksheet (not the module), which will run the macro 'HideSheets' whenever the value in cell C9 changes.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$9" Then
Call HideSheets
End If
End Sub

Running a macro automatically

I want a macro to run automatically everytime I navigate to a specific worksheet. I know this is possible because there is another macro on the worksheet that updates information automatically, but I can't seem to figure out how to set it so that my new macro will run automatically. Note all of the macros are in the same folder "Modules."
I think this might be along the lines of what you need. If you are in the VBA editor, on the left navigator pane, double click the sheet you are interested in having run the code automatically. In the window that opens, on the upper left change the drop down to "Worksheet". Then in the upper right drop down, change the event handler to "Activate"
You should see a new blank sub generate:
Private Sub Worksheet_Activate()
'put some code here
End Sub
Now anytime you activate that sheet, any code you enter in that sub will be run automatically. You can look at the event handlers in the right drop and try other ones if they suite your needs better.

Resources