Hi guys,
I have a code that pastes some data in the next free row and creates formcontrol button in the cells next to this data:
When run, macro creates the Comment button named Comment50. When run again, the data is pasted correctly below the last entry, button is also created in the correct place, but its named Comment50 again (instead of Comment49).
The naming is important because of the "CommentButton_Click" macro that hides/unhides rows:
When both buttons are named Comment50 then clicking on either of them will hide rows that are below the topmost Comment50 button.
Appreciate any help/suggestions.
Thanks in advace!
I have a code that pastes some data in the next free row and creates formcontrol button in the cells next to this data:
Rich (BB code):
Sub
Dim NextRow As RangeDim NextComment As Range
Dim i As Integer
Set NextRow = Sheets(Me.ProjectName_Box.Text).Cells(Rows.Count, 2).End(xlUp).Offset(6, 0)
Set NextComment = NextRow.Offset(0, 5)
Sheets("Template").Select
Range("B5:E11").Select
Selection.Copy
Sheets(Me.ProjectName_Box.Text).Select
NextRow.PasteSpecial Paste:=xlPasteAll
ActiveSheet.Buttons.Add(NextComment.Left, NextComment.Top, 81, 14.25).Select
Selection.Caption = "Comment"
For i = 1 To 50
Selection.Name = "Comment" & i
Next i
Selection.OnAction = "CommentButton_Click"
When run, macro creates the Comment button named Comment50. When run again, the data is pasted correctly below the last entry, button is also created in the correct place, but its named Comment50 again (instead of Comment49).
The naming is important because of the "CommentButton_Click" macro that hides/unhides rows:
Rich (BB code):
Sub CommentButton_Click()
Dim Btn As Button
Set Btn = ActiveSheet.Buttons(Application.Caller)
With Btn.TopLeftCell.Offset(1, 0).Resize(5).EntireRow
.Hidden = Not .Hidden
End With
End Sub
When both buttons are named Comment50 then clicking on either of them will hide rows that are below the topmost Comment50 button.
Appreciate any help/suggestions.
Thanks in advace!