ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Add/Delect Macro (https://www.excelbanter.com/excel-worksheet-functions/158744-add-delect-macro.html)

Chris

Add/Delect Macro
 
I have set up a add and a delete macro in my WB. I want the user to be able
to delete indivual lines or add a line beneth the add button. I set it up to
use hyperlink text by writing a macro on the sheet code. The Add button is in
column "L" or "12". The delete button is in column "M" or "13". The problem I
am having is it add or delete at the top and not the row inwhich the
hyperlink lies. Below are my current macros. Any help is greatly appreciated.
Thank you :)

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Column = 13 Then Application.Run "'Unit Trend cost out
v1.xls'! del"
If Target.Range.Column = 13 Then Exit Sub
Rows(ActiveCell.Row).Select
Selection.Copy
Selection.Insert Shift:=xlDown
Rows(ActiveCell.Row).Select
Application.CutCopyMode = False

End Sub

Sub del()
ActiveCell.Select
Rows(ActiveCell.Row).Select
Selection.Copy
Rows(ActiveCell.Row).Select
Selection.Delete Shift:=xlDown
Rows(ActiveCell.Row).Select
End Sub


JNW

Add/Delect Macro
 
This happens because your target for each hyperlink is probably pointing to
A1 or another reference above your links. When the code runs the activecell
gets set as the target range first.

I'm not sure how to fix this since hyperlink targets are not updated when
rows are added and deleted.
--
JNW


"Chris" wrote:

I have set up a add and a delete macro in my WB. I want the user to be able
to delete indivual lines or add a line beneth the add button. I set it up to
use hyperlink text by writing a macro on the sheet code. The Add button is in
column "L" or "12". The delete button is in column "M" or "13". The problem I
am having is it add or delete at the top and not the row inwhich the
hyperlink lies. Below are my current macros. Any help is greatly appreciated.
Thank you :)

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Column = 13 Then Application.Run "'Unit Trend cost out
v1.xls'! del"
If Target.Range.Column = 13 Then Exit Sub
Rows(ActiveCell.Row).Select
Selection.Copy
Selection.Insert Shift:=xlDown
Rows(ActiveCell.Row).Select
Application.CutCopyMode = False

End Sub

Sub del()
ActiveCell.Select
Rows(ActiveCell.Row).Select
Selection.Copy
Rows(ActiveCell.Row).Select
Selection.Delete Shift:=xlDown
Rows(ActiveCell.Row).Select
End Sub



All times are GMT +1. The time now is 08:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com