Hyperlink in VBA with next line code

Sikorsky27

New Member
Joined
Jun 24, 2021
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
I have it to were it I create new data and it puts all the information in 4 different sheets on a next line bases. The last thing I need is for it to auto hyperlink with my VBA submit button on my first sheet to highlight a range on my second sheet. Can anyone give me a head start on the code for this.
 

Attachments

  • Example.PNG
    Example.PNG
    30.3 KB · Views: 4

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Right click on your button and click "assign macro", then click new. You'll get something like this
VBA Code:
Sub Button1_Click()

End Sub

What ever code you put in here it will do
For instance, The below will highlight in yellow the A1 cell in Sheet1
VBA Code:
Sub Button1_Click()
Sheet1.Range("A1").Interior.Color = vbYellow
End Sub
 
Upvote 0
Right click on your button and click "assign macro", then click new. You'll get something like this
VBA Code:
Sub Button1_Click()

End Sub

What ever code you put in here it will do
For instance, The below will highlight in yellow the A1 cell in Sheet1
VBA Code:
Sub Button1_Click()
Sheet1.Range("A1").Interior.Color = vbYellow
End Sub
Thank you for your response. However, I am not looking to highlight just select like it can be seen in the picture. I can do that with no problem but I am trying to get it into my VBA code where it does it by itself so I don't have to manually do it.
 
Upvote 0
So you'll need to be a bit less vague on the details, whats the criteria for highlighting on other sheets, how does the button know what to highlight, you know. Juat need some logic to program with.
Best way of doing that, is: I you were going to do it manually, what would you look for to make that decision that those spacific cells need to be highlighted
When you say you have it where it put the data in the other 4 sheets, does it do this by VBA or formula
 
Upvote 0
This is my VBA... When it unmerges at "B2:C2" (Marked in Green) The information in B2 gets pasted on "shtData.Range A" I need it to also hyperlink the data in A to go to select a range of tiles on "shtTracker" automatically select sheet "tracker" range A:Q but its current number since it goes to last row every time I submit information. Is this a better?

Sub Submit1()

Const FIRSTROW As Long = 50

Dim shtAdding As Worksheet
Dim shtData As Worksheet
Dim shtTracker As Worksheet
Dim shtArchive As Worksheet
Dim shtAllData As Worksheet
Dim i As Long
Dim NextRow As Long

With ThisWorkbook
Set shtAdding = .Worksheets("Adding")
Set shtData = .Worksheets("Data")
Set shtTracker = .Worksheets("Tracker")
Set shtArchive = .Worksheets("Archive")
Set shtAllData = .Worksheets("All Data.Formula")
End With

With shtData
NextRow = .Cells(.Rows.Count, "B").End(xlUp).Row + 1
If NextRow < FIRSTROW Then
NextRow = FIRSTROW
End If
End With

With shtAdding
.Range("B2:C2").UnMerge

With .Range("B2")
.Copy Destination:=shtData.Range("A" & NextRow)
.Copy Destination:=shtData.Range("J" & NextRow)
.Copy Destination:=shtTracker.Range("A" & NextRow)
.Copy Destination:=shtArchive.Range("A" & NextRow)
.Copy Destination:=shtArchive.Range("J" & NextRow)
.Copy Destination:=shtArchive.Range("S" & NextRow)
.Copy Destination:=shtArchive.Range("AB" & NextRow)
.Copy Destination:=shtAllData.Range("A" & NextRow)
End With

.Range("C3:C9").Copy
shtData.Range("B" & NextRow).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, Transpose:=True
shtData.Range("K" & NextRow).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, Transpose:=True

shtAdding.Range("C10").Copy
shtTracker.Range("O" & NextRow).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, Transpose:=True

.Range("B2:C9,C10").ClearContents
.Range("B2:C2").Merge
End With

Application.CutCopyMode = False

ThisWorkbook.Worksheets("Adding").Visible = False
ThisWorkbook.Worksheets("Tracker").Visible = True
ThisWorkbook.Worksheets("Data").Visible = True
ThisWorkbook.Worksheets("All Data.Formula").Visible = True
ThisWorkbook.Worksheets("Archive").Visible = True
ThisWorkbook.Worksheets("Tracker").Activate
End Sub
 
Upvote 0
So this is how you create cell hyperlinks, is this what you wanted to use?
VBA Code:
    shtData.Hyperlinks.Add Anchor:=shtData.Range("A" & NextRow), Address:="", SubAddress:= _
        "shtTracker!F20", TextToDisplay:=shtAdding.Range("B2").Value
 
Upvote 0
Hi @Sikorsky27, I'm afraid, like @EFANYoutube, I don't quite understand what you exactly want. You want to have something highlighted, but it's not clear to me what. As far as I'm concerned, the image of your post #1 is not clear in that either, nothing is marked there.
Could it be the data you just copied? And if that's what you mean, that raises some other questions. Should the target worksheet be displayed on your screen when code finishes? Should on the next submit using your button this (so at that point meanwhile the previous) highlighting be made undone?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,487
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top