Offset not working in VB

that_one_girl

New Member
Joined
Mar 22, 2017
Messages
43
Hello Everyone,

I have a column with a drop-down list of staff to select for a particular task (starts in H3)

I have the following code programmed so that after the Employees have been assigned, management can run the macro to change the employees initials from the drop-down list, into an email hyperlink that he can just click it to send them an email notification of the assignment.

Below is my code. When I run it, it works great on the first cell!

But need it to skip anything that is already a hyperlink, and I need it to move down one row, same column, and repeat until it hits an empty cell.

Can anyone help?

Sub Hyperlink_Function()

Range("H3").Select

If ActiveCell.FormulaR1C1 = "VH" = True Then
ActiveCell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"mailto:VHeza@dir.ca.gov?subject=You%20have%20a%20new%20training%20assignment" _
, TextToDisplay:="VH"

ElseIf ActiveCell.FormulaR1C1 = "ML" = True Then
ActiveCell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"mailto:Mloupe@dir.ca.gov?subject=You%20have%20a%20new%20training%20assignment" _
, TextToDisplay:="ML"

ElseIf ActiveCell.FormulaR1C1 = "MC" = True Then
ActiveCell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"mailto:MChristian@dir.ca.gov?subject=You%20have%20a%20new%20training%20assignment" _
, TextToDisplay:="MC"


ElseIf ActiveCell.FormulaR1C1 = "M | S" = True Then
ActiveCell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"mailto:MChristian@dir.ca.gov;%20SBFlores@dir.ca.gov?subject=You%20have%20a%20new%20training%20assignment%20with%20a%20partner" _
, TextToDisplay:="M | S"


ElseIf ActiveCell.FormulaR1C1 = "SF" = True Then
ActiveCell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"mailto:SBFlores@dir.ca.gov?subject=You%20have%20a%20new%20training%20assignment" _
, TextToDisplay:="SF"

ElseIf ActiveCell.FormulaR1C1 = "AL" = True Then
ActiveCell.Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
"mailto:ALazzara@dir.ca.gov?subject=You%20have%20a%20new%20training%20assignment" _
, TextToDisplay:="AL"

ActtiveCell.Offset(1, 0).Select

ElseIf ActiveCell.FormulaR1C1 = "" = True Then

End If

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi there,

This will stop at the first cell from H3 that doesn't have a hyperlink in it - is that what you're after?

Code:
Option Explicit
Sub Macro1()

    Application.ScreenUpdating = False
    
    Range("H3").Select
    
    Do Until ActiveCell.Hyperlinks.Count = 0 'Adapted from www.ozgrid.com/forum/showthread.php?t=74922
        ActiveCell.Offset(1, 0).Select
    Loop
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Almost...............I need it to stop at a cell with a hyperlink, and/or a cell that is blank (no text)



Hi there,

This will stop at the first cell from H3 that doesn't have a hyperlink in it - is that what you're after?

Code:
Option Explicit
Sub Macro1()

    Application.ScreenUpdating = False
    
    Range("H3").Select
    
    Do Until ActiveCell.Hyperlinks.Count = 0 'Adapted from www.ozgrid.com/forum/showthread.php?t=74922
        ActiveCell.Offset(1, 0).Select
    Loop
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
I was able to use your code and modify it, and I got it working now! THANK YOU!!

Hi there,

This will stop at the first cell from H3 that doesn't have a hyperlink in it - is that what you're after?

Code:
Option Explicit
Sub Macro1()

    Application.ScreenUpdating = False
    
    Range("H3").Select
    
    Do Until ActiveCell.Hyperlinks.Count = 0 'Adapted from www.ozgrid.com/forum/showthread.php?t=74922
        ActiveCell.Offset(1, 0).Select
    Loop
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,217,364
Messages
6,136,114
Members
449,993
Latest member
Sphere2215

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