Create a button to copy a template and update it from starting sheet automatically

slzaleski

New Member
Joined
May 7, 2024
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
AKBreedingProgram.xlsm
ABCDEFGHIJ
1OwnerCollar #Horse NameBred ToCreateSheetLBD14DHB60DEFD
2AKR315One Famous MissGolden Boi3/5/20243/19/20244/2/20245/4/20242/13/2025
3AKR317I Cant Help ItFDD3/6/20243/20/20244/3/20245/5/20242/14/2025
4AKR324The Stands Of CommCyber Monday2/11/20242/25/20243/10/20244/11/20241/21/2025
5AKOR50
6
Mares
Cell Formulas
RangeFormula
G2:G4G2=F2 + 14
H2:H4H2=F2 + 28
I2:I4I2=+F2 + 60
J2:J4J2=F2 + 345


AKBreedingProgram.xlsm
ABCDEFGH
1Collar #Horse NameBred ToFoaling Date
2
3
4DateL OvaryR OvaryFoldsFluidCxBredNotes
5
6
Template


AKBreedingProgram.xlsm
ABCDEFGH
1Collar #Horse NameBred ToFoaling Date
2R315One Famous MissGolden Boi
3
4DateL OvaryR OvaryFoldsFluidCxBredNotes
5
One Famous Miss


I'm trying to create a button in column E(didn't show it) (E2, E3, etc downward) to generate a copy of the template sheet, rename it and update some fields in it from the Mares sheet. I got that done. I do not know how many rows I will have so I must do them as needed thus reason for button. Is there a way to make the button update it's values upon a copy and paste like excel can do with regular cells. row 2 E2 button works as needed. E3 wondering if there is a way to know what line I'm on to use in the button1_click code automatically.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
not sure this is what you want, it will tell you what row the button shape is in.

in theory you can have a button, with the same macro, any where on you sheet and it will tell you what row it is in.

VBA Code:
Sub My_Macro()
r = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
MsgBox r
End Sub

hth,
Ross
 
Upvote 0
Here is my button code. Any help appreciated?

Sub Button1_Click()

Dim R As Integer, C As Integer
'copy sheet from template
'Sheets("Template").Copy After:=Sheets("Mares")
Sheets("Template").Copy After:=Sheets(Sheets.Count)

ActiveSheet.Name = Sheets("Mares").Range("C2").Value
'Obtain current row in Mares sheet
R = Sheets("Mares").Shapes(Application.Caller).TopLeftCell.Row

'update New ActiveSheet row 2 column 1, 2, 3 from Mares sheet data
ActiveSheet.Range("a2").Value = Sheets("Mares").Cells(R, 1).Value
ActiveSheet.Range("b2").Value = Sheets("Mares").Range(R, 2).Value
ActiveSheet.Range("c2").Value = Sheets("Mares").Range(R, 3).Value

End Sub
 
Upvote 0
Here is my button code. Any help appreciated?

Sub Button1_Click()

Dim R As Integer, C As Integer

R = ActiveCell.Row
'C = Sheets("Mare").Column

'copy sheet from template
Sheets("Template").Copy After:=Sheets(Sheets.Count)

ActiveSheet.Name = Sheets("Mares").Range("C2").Value
'Obtain current row in Mares sheet
'R = Sheets("Mares").Shapes(Application.Caller).TopLeftCell.Row

'update New ActiveSheet row 2 column 1, 2, 3 from Mares sheet data
ActiveSheet.Range("a2").Value = Sheets("Mares").Cells(R, 1).Value
ActiveSheet.Range("b2").Value = Sheets("Mares").Cells(R, 2).Value
ActiveSheet.Range("c2").Value = Sheets("Mares").Cells(R, 3).Value

End Sub
This seems to work except I'm getting the wrong row of the Mares sheet. I want the row the button is located on.
 
Upvote 0
start a new sheet. add a shape. assign macro below to the shape. run it and note the value returned for r, now move the shape all around the worksheet, note the value of R changes as you move the shape around.

VBA Code:
Sub My_Macro()
r = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
MsgBox r
End Sub
 
Upvote 0
start a new sheet. add a shape. assign macro below to the shape. run it and note the value returned for r, now move the shape all around the worksheet, note the value of R changes as you move the shape around.

VBA Code:
Sub My_Macro()
r = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
MsgBox r
End Sub
Thank you I got it. Thank you Thank you. You got me thinking. I couldn't get around errors.

Sub My_Macro()
'Obtain current row in Mares sheet
R = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
Tag = Sheets("Mares").Cells(R, 2).Value
HName = Sheets("Mares").Cells(R, 3).Value
Stallion = Sheets("Mares").Cells(R, 4).Value

'MsgBox R
'MsgBox Tag
'MsgBox HName
'MsgBox Stallion

'copy sheet from template
Sheets("Template").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = HName
'update New ActiveSheet row 2 column 1, 2, 3 from Mares sheet data
ActiveSheet.Range("a2").Value = Tag
ActiveSheet.Range("b2").Value = HName
ActiveSheet.Range("c2").Value = Stallion

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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