Hi,
I have the below code, which adds buttons(shapes) to every cell from range A2:A200.
I would like this to be more dynamic, thus the desired result will be for this to add buttons based on an adjacent column, let's say Column B.
So if column B has data until line 40 i would like to have on Column A 40 buttons.
Code below:
```
'The Line Break Buttons (Break)
Sub breakButton()
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Application.ScreenUpdating = False
Range("A2:A200").Select
Dim btn As Button
Dim t As Range
' Find the First & Last Row number of selection
Dim x As Long, y As Long
x = Selection.Rows(1).Row
y = Selection.Rows.Count + x - 1
For i = x To y ' Loop from first row to last row
Set t = ActiveSheet.Range(Cells(i, 1), Cells(i, 1))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "btn_Click1"
.Caption = "Break " & i
.Name = "Break " & i
End With'
Next i
Application.ScreenUpdating = True
End Sub
```
As an extra question, just for me not to post another thread.
I would like that when i click the button (The one assigned to .OnAction in the formula) to copy cells a b c from the active cell, below.
Basically what i am trying to do is add more buttons below whenever i add new raw data to my spreadsheet.
I have tried this... I can copy the cell contents, just don't know how to paste them on the cell below. Did try an offset function but it doesn't seem to work on this type of function
```
Sub btn_Click1()
'Intersect(ActiveSheet.Shapes(Application.Caller).TopLeftCell.EntireRow, Range("D:V")).Insert xlShiftDown
'Intersect(ActiveSheet.Shapes(Application.Caller).TopLeftCell.EntireRow, Range("D:V")).Clear
Intersect(ActiveSheet.Shapes(Application.Caller).TopLeftCell.EntireRow, Range("D:V")).Copy
End Sub
```
I have the below code, which adds buttons(shapes) to every cell from range A2:A200.
I would like this to be more dynamic, thus the desired result will be for this to add buttons based on an adjacent column, let's say Column B.
So if column B has data until line 40 i would like to have on Column A 40 buttons.
Code below:
```
'The Line Break Buttons (Break)
Sub breakButton()
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Application.ScreenUpdating = False
Range("A2:A200").Select
Dim btn As Button
Dim t As Range
' Find the First & Last Row number of selection
Dim x As Long, y As Long
x = Selection.Rows(1).Row
y = Selection.Rows.Count + x - 1
For i = x To y ' Loop from first row to last row
Set t = ActiveSheet.Range(Cells(i, 1), Cells(i, 1))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "btn_Click1"
.Caption = "Break " & i
.Name = "Break " & i
End With'
Next i
Application.ScreenUpdating = True
End Sub
```
As an extra question, just for me not to post another thread.
I would like that when i click the button (The one assigned to .OnAction in the formula) to copy cells a b c from the active cell, below.
Basically what i am trying to do is add more buttons below whenever i add new raw data to my spreadsheet.
I have tried this... I can copy the cell contents, just don't know how to paste them on the cell below. Did try an offset function but it doesn't seem to work on this type of function
```
Sub btn_Click1()
'Intersect(ActiveSheet.Shapes(Application.Caller).TopLeftCell.EntireRow, Range("D:V")).Insert xlShiftDown
'Intersect(ActiveSheet.Shapes(Application.Caller).TopLeftCell.EntireRow, Range("D:V")).Clear
Intersect(ActiveSheet.Shapes(Application.Caller).TopLeftCell.EntireRow, Range("D:V")).Copy
End Sub
```