WORD VBA - Userform - Auto fill - vba

I am trying to create a user form in VBA on Microsoft word.
I have been following http://gregmaxey.com/word_tip_pages/create_employ_userform.html
to create the form.
I am very very very new to programming and have basically just been teaching myself as I go.
I get a "compile error: Sub of Function not defined" when I try and step through Call UF
I've attached the whole code for you to look at and tell me where I've gone wrong, happy for any suggestions.
Module - modMain
Option Explicit
Sub Autonew()
Create_Reset_Variables
Call UF
lbl_Exit:
Exit Sub
End Sub
Sub Create_Reset_Variables()
With ActiveDocument.Variables
.Item("varFormNumber").Value = " "
.Item("varTitle").Value = " "
.Item("varGivenName").Value = " "
.Item("varFamilyName").Value = " "
.Item("varStreet").Value = " "
.Item("varSuburb").Value = " "
.Item("varState ").Value = " "
.Item("varPostCode").Value = " "
.Item("varInterviewDate").Value = " "
End With
myUpdateFields
lbl_Exit:
Exit Sub
End Sub
Sub myUpdateFields()
Dim oStyRng As Word.Range
Dim iLink As Long
iLink = ActiveDocument.Sections(1).Headers(1).Range.StoryType
For Each oStyRng In ActiveDocument.StoryRanges
Do
oStyRng.Fields.Update
Set oStyRng = oStyRng.NextStoryRange
Loop Until oStyRng Is Nothing
Next
End Sub
Form - frmLetter13
Option Explicit
Public boolProceed As Boolean
Sub CalUF()
Dim oFrm As frmLetter13
Dim oVars As Word.Variables
Dim strTemp As String
Dim oRng As Word.Range
Dim i As Long
Dim strMultiSel As String
Set oVars = ActiveDocument.Variables
Set oFrm = New frmLetter13
With oFrm
.Show
If .boolProceed Then
oVars("varFormNumber").Value = TextBoxFormNumber
oVars("varTitle").Value = ComboBoxTitle
oVars("varGivenName").Value = TextBoxGivenName
oVars("varFamilyName").Value = TextBoxFamilyName
oVars("varStreet").Value = TextBoxStreet
oVars("varSuburb").Value = TextBoxSuburb
oVars("varState").Value = ComboBoxState
oVars("varPostCode").Value = TextBoxPostCode
oVars("varInterviewDate").Value = TextBoxInterviewDate
End If
Unload oFrm
Set oFrm = Nothing
Set oVars = Nothing
Set oRng = Nothing
lbl_Exit
Exit Sub
End Sub
Private Sub TextBoxFormNumber_Change()
End Sub
Private Sub Userform_Initialize()
With ComboBoxTitle
.AddItem "Mr"
.AddItem "Mrs"
.AddItem "Miss"
.AddItem "Ms"
End With
With ComboBoxState
.AddItem "QLD"
.AddItem "NSW"
.AddItem "ACT"
.AddItem "VIC"
.AddItem "TAS"
.AddItem "SA"
.AddItem "WA"
.AddItem "NT"
End With
lbl_Exit:
Exit Sub
End Sub
Private Sub CommandButtonCancel_Click()
Me.Hide
End Sub
Private Sub CommandButtonClear_Click()
Me.Hide
End Sub
Private Sub CommandButtonOk_Click()
Select Case ""
Case Me.TextBoxFormNumber
MsgBox "Please enter the form number."
Me.TextBoxFormNumber.SetFocus
Exit Sub
Case Me.ComboBoxTitle
MsgBox "Please enter the Applicant's title."
Me.ComboBoxTitle.SetFocus
Exit Sub
Case Me.TextBoxGivenName
MsgBox "Please enter the Applicant's given name."
Me.TextBoxGivenName.SetFocus
Exit Sub
Case Me.TextBoxFamilyName
MsgBox "Please enter the Applicant's family name."
Me.TextBoxFamilyName.SetFocus
Exit Sub
Case Me.TextBoxStreet
MsgBox "Please enter the street address."
Me.TextBoxStreet.SetFocus
Exit Sub
Case Me.TextBoxSuburb
MsgBox "Please enter the suburb."
Me.TextBoxSuburb.SetFocus
Exit Sub
Case Me.ComboBoxState
MsgBox "Please enter the state."
Me.ComboBoxState.SetFocus
Exit Sub
Case Me.TextBoxPostCode
MsgBox "Please enter the postcode."
Me.TextBoxPostCode.SetFocus
Exit Sub
Case Me.TextBoxInterviewDate
MsgBox "Please enter the interview date."
Me.TextBoxInterviewDate.SetFocus
Exit Sub
End Select
'Set value of a public variable declared at the form level.'
Me.boolProceed = True
Me.Hide
lbl_Exit:
Exit Sub
End Sub

There are a couple of issues here.
The first issue is that you do not have a routine named UF for Call UF to call.
The routine that you have named CalUF should not be in the code for the UserForm but should be in modMain and renamed CallUF.
There is no need to include an exit point in your routine as you don't have an error handler.
Your AutoNew routine could be rewritten as:
Sub Autonew()
Create_Reset_Variables
CallUF
End Sub

I have commented your sub myUpdateFields for you.
Sub myUpdateFields()
Dim oStyRng As Word.Range
Dim iLink As Long
iLink = ActiveDocument.Sections(1).Headers(1).Range.StoryType
' logically, iLink should be the StoryType of the first header in Section 1
' Why would this be needed in all StoryRanges?
' Anyway, it is never used. Why have it, then?
' This loops through all the StoryRanges
For Each oStyRng In ActiveDocument.StoryRanges
' This also loops through all the StoryRanges
Do
oStyRng.Fields.Update
Set oStyRng = oStyRng.NextStoryRange
Loop Until oStyRng Is Nothing
'And after you have looped through all the StoryRanges
' Here you go back and start all over again.
Next oStyRng End Sub
Frankly, I don't know if the Do loop does anything here. Perhaps it does. Read up about the NextStoryRange property here. I also don't know if using the same object variable in the inside loop upsets the outside loop. I don't know these things because I never needed to know them. Therefore I wonder why you need them on your second day in school.
You are setting a number of document variables. These could be linked to REF fields in your document which you wish to update. I bet your document has only one section, no footnotes and no textboxes with fields in them. Therefore I think that the following code should do all you need, if not more.
Sub myUpdateFields2()
Dim Rng As Word.Range
For Each Rng In ActiveDocument.StoryRanges
Rng.Fields.Update
Next Rng
End Sub
To you, the huge advantage of this code is that you fully understand it. Towards this end I have avoiding using a name like oStyRng (presumably meant to mean "StoryRange Object"). It is true that a Word.Range is an object. It is also true that the procedure assigns a StoryRange type of Range to this variable. But the over-riding truth is that it is a Word.Range and therefore a Range. Code will be easier to read when you call a spade a spade, and not "metal object for digging earth". My preferred variable name for a Word.Range is, therefore, "Rng". But - just saying. By all means, use names for your variables which make reading your code easy for yourself.

Related

Is there a way to choose the location in Outlook for appointments and meetings from a user-created drop down list?

My employer requires some pretty specific information in the "location" field of my Outlook calendar appointments and meetings. It's time consuming to open each meeting invite, etc. to add the specific information. I have a list of possible locations, and I'm looking for a way to select from that list easily...I have found some VBA that will allow for a drop down on a template to select the subject, but not the location. And, I'm not sure that will work for meeting invites that I don't create.
Any help would be greatly appreciated!
Here's the code I found related to the drop down for the subject.
'** The following code goes in a userform **
' Adapted for a single choice
Private Sub cmdOkay_Click()
Dim i As Long
Dim msg As String
Dim Check As String
Dim currItem As MailItem
'Generate a list of the selected items
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
msg = .List(i)
Exit For
End If
Next i
End With
If msg = vbNullString Then
'If nothing was selected, tell user and let them try again
MsgBox "Nothing was selected! Please make a selection!"
Exit Sub
Else
Set currItem = Application.ActiveInspector.currentItem
currItem.Subject = msg
Unload Me
End If
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
'Clear the rowsource in case it has been set
.RowSource = ""
'Add the items
.AddItem ("Cat")
.AddItem ("Dog")
.AddItem ("Gerbil")
.AddItem ("Lizard")
.AddItem ("Rat")
.AddItem ("Snake")
.AddItem ("Turtle")
End With
End Sub
'** The following code goes in a standard module **
Sub Launch()
'This code will launch the userform
UserForm1.Show
End Sub
I also found this code, but I would need to change this to allow for choosing different locations.
Option Explicit
Sub InsertConfCallInfo()
Dim myItem As AppointmentItem
On Error GoTo lbl_Exit
Set myItem = ActiveInspector.CurrentItem
myItem.Location = "CALL: (866) 555-1212 / CODE: 9854101812"
'myItem.Display 'Not required as the item is already displayed.
lbl_Exit:
Exit Sub
End Sub
You can develop a VBA macro with a user form from where you could choose the Location for appointment items. The Userform Drop down list VBA page explains how to populate the drop down control at startup.
Also you may consider create a COM add-in where you could create a form region with a drop down control. It is up to you which way is to choose.
Once you verify currItem is an AppointmentItem you can update .Location.
'** The following code goes in a userform **
Option Explicit
Private Sub cmdOkay_Click()
Dim i As Long
Dim msg As String
Dim currItem As Object
Set currItem = ActiveInspector.CurrentItem
If TypeOf currItem Is AppointmentItem Then
'Generate a list of the selected items
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
msg = .List(i)
Exit For
End If
Next i
End With
If msg = vbNullString Then
'If nothing was selected, tell user and let them try again
MsgBox "Nothing was selected! Please make a selection!"
Else
currItem.Location = msg
Unload Me
End If
End If
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
'Clear the rowsource in case it has been set
.RowSource = ""
'Add the items
.AddItem ("CALL: (866) 555-1212 / CODE: 9854101812")
.AddItem ("Dog")
.AddItem ("Gerbil")
.AddItem ("Lizard")
.AddItem ("Rat")
.AddItem ("Snake")
.AddItem ("Turtle")
End With
End Sub
'** The following code goes in a standard module **
Sub Launch()
'This code will launch the userform
UserForm1.Show
End Sub

How to use Public Range value in multiple user forms?

I have a userform which will ask for a number that is then getting looked up in a spreadsheet, saving that range in a variable. When it's found the number, it will hide the first userform and bring up the second one, but in order for me to proceed with the update, I will need to use the same range that I've previously set against my variable in userform1, any idea how to do that? I have declared it as a Public variable but it still doesn't work. Code as it follows:
UserForm1:
Public FillRange As Range
Public BKref As Variant
Private Sub CommandButton1_Click()
On Error GoTo errhndlr:
Set FillRange = Sheets("Loader").Cells.Find(TextRef.Value).Offset(0, 2)
BKref = TextRef.Value
If Not FillRange = "" Then
UserForm1.Hide
UserForm2.Show
Exit Sub
ElseIf FillRange = "" Then
MsgBox "Booking Reference cannot be empty!", vbCritical, "Error: No Booking Ref."
UserForm1.Hide
Exit Sub
Else
MsgBox "Unexpected error, please re-start and try again. If you had this message more than 2 times, please update the line manually.", vbCritical, "Error"
UserForm1.Hide
Exit Sub
End If
Exit Sub
errhndlr:
MsgBox "Booking reference not found, please double-check that the booking reference you've entered is correct, alternatively update it manually.", vbCritical, "Error"
UserFrom1.Hide
End Sub
UserForm2:
Private Sub CommandButton1_Click()
FillRange = TextPloaded.Value
FillRange.Offset(0, 2) = TextTime.Value
FillRange.Offset(0, 3) = TextLoader.Value
If Not TextComm.Value = "" Then
FillRange.Offset(0, 4) = TextComm.Value
ElseIf TextComm.Value = "" Then
FillRange.Offset(0, 4) = ""
End If
If Not FillRange = FillRange(0, -1) Then
MsgBox "Actual and Planned pallets doesn't match, please highlight the diescrepancies on the assembly sheet!"
BKref = FillRange.Offset(0, -2)
Sheets("Assembly").Activate
Sheets("Assembly").Rows(1).AutoFilter Field:=16, Criteria1:=BKref
UserForm2.Hide
Else
UserForm2.Hide
UserForm1.Show
End If
End Sub
If you make use of Option Explicit in every module/userform etc. This forces you to declare all variables properly and shows a message if a variable is not declared.
The issue is that if you declare Public FillRange As Range in Userform1 the variable is only valid in Userform1 but not in Userform2.
So I recommend to decare the variable in a Module instead of Userform1. This way it is accessible everywhere.
Alternative
You can access a public Userform1 variable in Userfrom2 by Userform1.FillRange
Add a property in your first form:
Property Get FillRange() As Range
Set FillRange = Range("A1")
End Property
And read it from your second form:
Dim FillRange
Set FillRange = UserForm1.FillRange

Cancel Button makes a selection rather than cancelling

I'm using the following code behind an Outlook UserForm called Select_Email_Template.
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Account Amendment Non SC"
.AddItem "Account Amendment SC Application Received"
.AddItem "Account Amendment SC"
.AddItem "Account Creation Non SC"
.AddItem "Account Creation SC Application Received"
.AddItem "Account Creation SC"
.AddItem "Export Function"
.AddItem "Password Reset"
End With
End Sub
Private Sub btnOK_Click()
lstNum = ComboBox1.ListIndex
Unload Me
End Sub
Private Sub btnCancel_Click()
Unload Select_Email_Template
End Sub
The ComboBox allows the user to select an email template. When one is selected and OK clicked, the template is opened in Outlook.
This is the code which opens the templates:
Public lstNum As Long
Public Sub Email_Templates()
Dim outMail As Outlook.MailItem
Select_Email_Template.Show
Select Case lstNum
' Following the listbox entries
Case 0
Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment Non SC.oft")
Case 1
Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment SC Application Received.oft")
Case 2
Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment SC.oft")
Case 3
Set outMail = CreateItemFromTemplate("TemplatePath\Account Creation Non SC.oft")
Case 4
Set outMail = CreateItemFromTemplate("TemplatePath\Account Creation SC Application Received.oft")
Case 5
Set outMail = CreateItemFromTemplate("TemplatePath\Account Creation SC.oft")
Case 6
Set outMail = CreateItemFromTemplate("TemplatePath\Export Function.oft")
Case 7
Set outMail = CreateItemFromTemplate("TemplatePath\Export Function.oft")
End Select
' Use for a specific purpose not randomly
' On Error Resume Next
With outMail
.Display
End With
' On Error GoTo 0
cleanup:
Set outMail = Nothing
End Sub
When the user clicks Cancel, the form closes but the first template from the list opens in Outlook.
How can I close the form without this first template opening at the same time?
Whilst it is possible to solve the issue by using a global variable, a much neater solution is use the UserForm.Tag property to pass a result back to the main procedure.
Be aware that unloading the UserForm also removes the tag value, so you need to hide the UserForm in the click handlers, use the tag value in the main procedure, and then unload the UserForm.
Select_Email_Template UserForm code:
Private Sub UserForm_Initialize()
Dim varTemplateName As Variant
With ComboBox1
For Each varTemplateName In Templates(NameOnly:=True) ' Templates() also works
.AddItem varTemplateName
Next
End With
End Sub
Private Sub btnOK_Click()
Me.Tag = Me.ComboBox1.ListIndex
Me.Hide
End Sub
Private Sub btnCancel_Click()
Me.Tag = -1
Me.Hide
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = VBA.VbQueryClose.vbFormControlMenu Then
Cancel = True
btnCancel_Click
End If
End Sub
Non-Class Module code:
Public Sub Email_Templates()
With Select_Email_Template
.Show
If .Tag <> -1 Then
CreateItemFromTemplate(Templates(.Tag, FullPath:=True)).Display ' Templates(.Tag) also works
End If
End With
Unload Select_Email_Template
End Sub
Public Function Templates _
( _
Optional ByVal plngIndex As Long = -1 _
, Optional ByVal NameOnly As Boolean = False _
, Optional ByVal FullPath As Boolean = False _
) _
As Variant
Const strcTemplatesDir As String = "<TemplatesPath>\"
Const strcTemplateExtension As String = ".oft"
Static avarTemplateNames As Variant
If IsEmpty(avarTemplateNames) Then
avarTemplateNames = Array _
( _
"Account Amendment Non SC" _
, "Account Amendment SC Application Received" _
, "Account Amendment SC" _
, "Account Creation Non SC" _
, "Account Creation SC Application Received" _
, "Account Creation SC" _
, "Export Function" _
, "Export Function" _
)
End If
If plngIndex <> -1 Then
If NameOnly = True And FullPath = False Then
Templates = avarTemplateNames(plngIndex)
Else
Templates = strcTemplatesDir & avarTemplateNames(plngIndex) & strcTemplateExtension
End If
Else
Templates = avarTemplateNames
End If
End Function
Explanation:
The main idea here is to return, via the Select_Email_Template.Tag property, a -1 when the user clicks Cancel and a valid index (0 to 7 in your example) when the user clicks OK.
The code also redirects ALT+F4, clicking the close box (and its keyboard shortcut equivalent ALT+SPC;C), and any other method of closing the UserForm, to the cancel button's click handler.
I've also taken the liberty of refactoring your code so all the template data is declared once only and in one place only, i.e., in the Templates() function.
I've used a static variable in this function so that the array is only ever initialized once. You could just declare it with Dim and skip the empty check and it would still work just fine.
Note: If you are curious about my variable naming convention, it is based on RVBA.
The global variable lstnum is initially 0. Since you are using lstnum as the Select trigger make it -1, to conform to the norm.
Outlook Form To Select Email Template
Case -1
' -1 is what you want to use if nothing is selected
Following the method you are using to return the choice from the userform.
Private Sub btnCancel_Click()
lstNum = -1
Unload Select_Email_Template
End Sub
#IRHM I've got the following to work correctly. I've used MsgBoxes to test with, and tested each option. Try it. Once it looks like it's working for you, comment out or delete the unnecessary stuff, change the variable names and you should be good to go.
Sub Email_Templates()
Dim ComboBox1
Dim intCount As Integer
Dim intSelectedIndex As Integer
Dim myNum As Integer
'Dim outMail As Outlook.MailItem
Userform1.Show
myNum = Userform1.ComboBox1.ListIndex
If myNum = 0 Then
Goto Abort
Else
MsgBox ("Back to the main module")
Select Case myNum
Case 1
'Using MsgBox to test and make sure it's working
MsgBox "You selected Account Amendment Non SC - Option 1"
'Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment Non SC.oft")
Case 2
MsgBox "You selected Account Amendment SC Application Received - Option 2"
'Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment SC Application Received.oft")
Case 3
MsgBox "You Selected Account Amendment SC - Option 3"
'Set outMail = CreateItemFromTemplate("TemplatePath\Account Amendment SC.oft")
End Select
Abort:
End If
Unload UserForm1
End Sub
Put the following lines in the UserForm code module:
Sub btnCancel_Click()
MsgBox ("Cancel button selected")
Unload Me
End Sub
Sub btnOK_Click()
MsgBox ("OK Selected")
Me.Hide
End Sub
Sub UserForm_Initialize()
'Put all your AddItems here
With ComboBox1
.Clear
.AddItem "This should exit", 0
.AddItem "Selection 1", 1
.AddItem "Selection 2", 2
.AddItem "Selection 3", 3
End With
End Sub

Simplify code with loop

Hi I'm pretty new at the vba so please don't shoot my code :-).
I have a set of repaeting code's. I woukld like to simplify this code by using the code name with an increasing number. I can't get it to run. Can someone help me a bit on the road to get this going.
Below what I'm trying.
The second block is a part of the code now (it's 40 blocks of the same code only increasing the number)
Sub sheet41()
Dim i As Integer
Dim chkname As Integer
chkname = "SheetCheckBox" & i
i = 1
Do
i = i + 1
If chkname.Visible = False Then Exit Sub
If chkname.value = True Then
Sheets("Item_" & i).Select
Call Finalize
End If
Loop Until i = ThisWorkbook.Worksheets.Count
End Sub
This is the old code:
Sub Sheet1()
If SheetCheckBox1.Visible = False Then Exit Sub
If SheetCheckBox1.value = True Then
Sheets("Item_1").Select
Call Finalize
End If
End Sub
Sub Sheet2()
If SheetCheckBox2.Visible = False Then Exit Sub
If SheetCheckBox2.value = True Then
Sheets("Item_2").Select
Call Finalize
End If
End Sub
Sub Sheet3()
If SheetCheckBox3.Visible = False Then Exit Sub
If SheetCheckBox3.value = True Then
Sheets("Item_3").Select
Call Finalize
End If
End Sub
As you can see this should be possible to clean I asume.
This should do it. If finalize isn't called on a worksheet then the reason why is printed to the Immediate Window.
Sub ProcessWorkSheets()
Dim check As MSForms.CHECKBOX
Dim i As Integer
For i = 1 To Worksheets.Count
On Error Resume Next
Set check = Worksheets(i).OLEObjects("SheetCheckBox" & i).Object
On Error GoTo 0
If check Is Nothing Then
Debug.Print Worksheets(i).Name; " - Checkbox not found"
Else
If check.Visible And check.Value Then
Worksheets(i).Select
Call Finalize
Else
Debug.Print Worksheets(i).Name; " - Checkbox", "Visible", check.Visible, "Value:", check.Value
End If
End If
Set check = Nothing
Next
End Sub
If the checkboxes on the Sheet are ActiveX Controls, you can use this to access the checkboxes:
Sheets("sheet1").OLEObjects("chkTest").Object
if you want to change the value of a checkbox, use it like this:
Sheets("sheet1").OLEObjects("chkTest").Object.Value = True
now replace "sheet1" with your actual sheet name and change the "chkTest" to your string chkname
So your complete code should be like this:
Dim i As Integer
Dim sheetname As String
Dim chkname As String
sheetname = "YOUR SHEETNAME HERE"
For i = 1 To ThisWorkbook.Worksheets.Count Step 1
chkname = "SheetCheckBox" & i
If Sheets(sheetname).OLEObjects(chkname).Object.Visible = False Then Exit Sub
If Sheets(sheetname).OLEObjects(chkname).Object.Value = True Then
Sheets("Item_" & i).Select
Call Finalize
End If
Next i

How can i call a Sub using hyperlinks

I am newbie to VBA; I have a question:
How can I call sub to delete a cell in a sheet by using a Hyperlinks from another sheet.
A structure of the code is greatly appreciated.
Event handler in worksheet which contains the hyperlink:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.TextToDisplay = "Clear Cell" Then
ClearThatCell
End If
End Sub
Note there's also a Workbook-level event: use that if you'd like to be able to trap any hyperlink click in the workbook.
Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, _
ByVal Target As Hyperlink)
End Sub
Called code:
Sub ClearThatCell()
ThisWorkbook.Sheets("Sheet2").Range("A1").ClearContents
End Sub
' Public m_data_wks As Worksheet
Sub init_links
Dim v_r As Range, n_rows as Integer
Set v_r = m_data_wks.Cells(1, 1)
n_rows = 3 'is an example of filling up cells with hyperlinks
For I = 1 To n_rows
v_r.Value = I
'The key: adding hyperlink to the v_r cell with a special subaddress for alternative usage.
'The hyperlink looks like the ordinary but points to itself.
m_data_wks.Hyperlinks.Add Anchor:=v_r, Address:="", SubAddress:=v_r.Address(External:=False, RowAbsolute:=False, columnAbsolute:=False)
Set v_r = v_r.Offset(1)
Next I
end sub
'Private WithEvents App As Application
Private Sub App_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
Dim v_dst As Worksheet, v_index_s As String, v_index_i As Integer
'get_context sets v_dst the proper worksheet
'get_context Sh.Parent, v_dst
If v_dst Is Nothing Then Exit Sub
On Error GoTo Ext
'Using the value of the cell for choosing which to delete
v_index_s = CStr(Sh.Range(Target.SubAddress).Value)
If v_index_s = "#" Then
v_index_i = 0
Else
v_index_i = CLng(v_index_s)
End If
'Here the v_index_i points to the row instead of a cell for deleting
v_dst.Rows(v_index_i).Delete
Exit Sub
Ext:
If Err.Number <> 0 Then
MsgBox "Error occured while deleting by hyperlink: " & Err.Number & ", " & Err.Description, vbExclamation, "Non critical error"
Err.Clear
End If
End Sub