ryan james hardy
New Member
- Joined
- Sep 12, 2012
- Messages
- 19
Hi, i am looking for a macro that adds a new row of data. For example i have these rows below, where orange is input and white is derived from a formula. So ideally the macro would be assigned to a button which when clicked would have fields for the 8 orange cells and then automatically copy down the formula of the 2 white cells.
[TABLE="width: 1101"]
<colgroup><col style="width: 152pt; mso-width-source: userset; mso-width-alt: 6464;" width="202"> <col style="width: 54pt;" width="72"> <col style="width: 71pt; mso-width-source: userset; mso-width-alt: 3040;" width="95"> <col style="width: 59pt; mso-width-source: userset; mso-width-alt: 2496;" width="78"> <col style="width: 104pt; mso-width-source: userset; mso-width-alt: 4448;" width="139"> <col style="width: 74pt; mso-width-source: userset; mso-width-alt: 3136;" span="2" width="98"> <col style="width: 107pt; mso-width-source: userset; mso-width-alt: 4576;" width="143"> <col style="width: 131pt; mso-width-source: userset; mso-width-alt: 5568;" width="174"> <col style="width: 159pt; mso-width-source: userset; mso-width-alt: 6784;" width="212"> <col style="width: 54pt;" width="72"> <col style="width: 62pt; mso-width-source: userset; mso-width-alt: 2656;" width="83"> <tbody>[TR]
[TD="class: xl65, width: 202, bgcolor: transparent"]Staff[/TD]
[TD="class: xl65, width: 72, bgcolor: transparent"]Gender[/TD]
[TD="class: xl65, width: 95, bgcolor: transparent"]DOB[/TD]
[TD="class: xl65, width: 78, bgcolor: transparent"]Age[/TD]
[TD="class: xl65, width: 139, bgcolor: transparent"]Business unit number[/TD]
[TD="class: xl66, width: 98, bgcolor: transparent"]Type[/TD]
[TD="class: xl66, width: 98, bgcolor: transparent"]Start date[/TD]
[TD="class: xl66, width: 143, bgcolor: transparent"]Termination date[/TD]
[TD="class: xl65, width: 174, bgcolor: transparent"]Weeks employed[/TD]
[TD="class: xl65, width: 212, bgcolor: transparent"]Reason for termination[/TD]
[TD="class: xl67, width: 72, bgcolor: transparent"][/TD]
[TD="class: xl67, width: 83, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]Emma[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]F[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]7/05/1965[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]47[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]649[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Casual[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]1/05/2011[/TD]
[TD="class: xl71, bgcolor: #FFCC99"]13/01/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]37[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Termination with cause[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]Michele[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]F[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]4/01/1985[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]27[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]671[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Casual[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]4/05/2011[/TD]
[TD="class: xl71, bgcolor: #FFCC99"]6/03/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]44[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Other[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[TD="class: xl67, width: 83, bgcolor: transparent"]<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" oreferrelative="t" o:spt="75" coordsize="21600,21600"> <v:stroke joinstyle="miter"> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"> <v:f eqn="sum @0 1 0"> <v:f eqn="sum 0 0 @1"> <v:f eqn="prod @2 1 2"> <v:f eqn="prod @3 21600 pixelWidth"> <v:f eqn="prod @3 21600 pixelHeight"> <v:f eqn="sum @0 0 1"> <v:f eqn="prod @6 1 2"> <v:f eqn="prod @7 21600 pixelWidth"> <v:f eqn="sum @8 21600 0"> <v:f eqn="prod @7 21600 pixelHeight"> <v:f eqn="sum @10 21600 0"> </v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas> <vath o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"> <o:lock aspectratio="t" v:ext="edit"> </o:lock></vath></v:stroke></v:shapetype>[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]John[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]M[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]9/05/1963[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]49[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]670[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Permanent[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]5/05/2010[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]2/04/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]99.8[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Resignation[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]Stevo[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]M[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]4/06/1970[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]42[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]649[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Casual[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]6/05/2011[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]5/05/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]52.2[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Retirement[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]Mark[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]M[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]6/09/1959[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]53[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]672[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Part time[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]6/05/2011[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]6/05/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]52.2[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]End of Contract[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]
I tried this code as a test and it somewhat worked but didnt copy the formulas down.
Private Sub CommandButton1_Click()
End Sub
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Entry")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.Staff.Value
ws.Cells(iRow, 2).Value = Me.MF.Value
ws.Cells(iRow, 3).Value = Me.DOB.Value
ws.Cells(iRow, 5).Value = Me.Unit.Value
ws.Cells(iRow, 6).Value = Me.Type.Value
'clear the data
Me.Staff.Value = ""
Me.MF.Value = ""
Me.DOB.Value = ""
Me.Unit.Value = ""
Me.Type.Value = ""
Me.txtPart.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Staff_Click()
End Sub
Private Sub txtPart_Change()
End Sub
Private Sub UserForm_Click()
End Sub
[TABLE="width: 1101"]
<colgroup><col style="width: 152pt; mso-width-source: userset; mso-width-alt: 6464;" width="202"> <col style="width: 54pt;" width="72"> <col style="width: 71pt; mso-width-source: userset; mso-width-alt: 3040;" width="95"> <col style="width: 59pt; mso-width-source: userset; mso-width-alt: 2496;" width="78"> <col style="width: 104pt; mso-width-source: userset; mso-width-alt: 4448;" width="139"> <col style="width: 74pt; mso-width-source: userset; mso-width-alt: 3136;" span="2" width="98"> <col style="width: 107pt; mso-width-source: userset; mso-width-alt: 4576;" width="143"> <col style="width: 131pt; mso-width-source: userset; mso-width-alt: 5568;" width="174"> <col style="width: 159pt; mso-width-source: userset; mso-width-alt: 6784;" width="212"> <col style="width: 54pt;" width="72"> <col style="width: 62pt; mso-width-source: userset; mso-width-alt: 2656;" width="83"> <tbody>[TR]
[TD="class: xl65, width: 202, bgcolor: transparent"]Staff[/TD]
[TD="class: xl65, width: 72, bgcolor: transparent"]Gender[/TD]
[TD="class: xl65, width: 95, bgcolor: transparent"]DOB[/TD]
[TD="class: xl65, width: 78, bgcolor: transparent"]Age[/TD]
[TD="class: xl65, width: 139, bgcolor: transparent"]Business unit number[/TD]
[TD="class: xl66, width: 98, bgcolor: transparent"]Type[/TD]
[TD="class: xl66, width: 98, bgcolor: transparent"]Start date[/TD]
[TD="class: xl66, width: 143, bgcolor: transparent"]Termination date[/TD]
[TD="class: xl65, width: 174, bgcolor: transparent"]Weeks employed[/TD]
[TD="class: xl65, width: 212, bgcolor: transparent"]Reason for termination[/TD]
[TD="class: xl67, width: 72, bgcolor: transparent"][/TD]
[TD="class: xl67, width: 83, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]Emma[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]F[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]7/05/1965[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]47[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]649[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Casual[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]1/05/2011[/TD]
[TD="class: xl71, bgcolor: #FFCC99"]13/01/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]37[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Termination with cause[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]Michele[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]F[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]4/01/1985[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]27[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]671[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Casual[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]4/05/2011[/TD]
[TD="class: xl71, bgcolor: #FFCC99"]6/03/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]44[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Other[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[TD="class: xl67, width: 83, bgcolor: transparent"]<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" oreferrelative="t" o:spt="75" coordsize="21600,21600"> <v:stroke joinstyle="miter"> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"> <v:f eqn="sum @0 1 0"> <v:f eqn="sum 0 0 @1"> <v:f eqn="prod @2 1 2"> <v:f eqn="prod @3 21600 pixelWidth"> <v:f eqn="prod @3 21600 pixelHeight"> <v:f eqn="sum @0 0 1"> <v:f eqn="prod @6 1 2"> <v:f eqn="prod @7 21600 pixelWidth"> <v:f eqn="sum @8 21600 0"> <v:f eqn="prod @7 21600 pixelHeight"> <v:f eqn="sum @10 21600 0"> </v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas> <vath o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"> <o:lock aspectratio="t" v:ext="edit"> </o:lock></vath></v:stroke></v:shapetype>[/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]John[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]M[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]9/05/1963[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]49[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]670[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Permanent[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]5/05/2010[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]2/04/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]99.8[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Resignation[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]Stevo[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]M[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]4/06/1970[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]42[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]649[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Casual[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]6/05/2011[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]5/05/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]52.2[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Retirement[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl68, bgcolor: #FFCC99"]Mark[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]M[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]6/09/1959[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]53[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]672[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]Part time[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]6/05/2011[/TD]
[TD="class: xl69, bgcolor: #FFCC99"]6/05/2012[/TD]
[TD="class: xl70, bgcolor: #F2F2F2"]52.2[/TD]
[TD="class: xl68, bgcolor: #FFCC99"]End of Contract[/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[TD="class: xl67, bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]
I tried this code as a test and it somewhat worked but didnt copy the formulas down.
Private Sub CommandButton1_Click()
End Sub
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Entry")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.Staff.Value
ws.Cells(iRow, 2).Value = Me.MF.Value
ws.Cells(iRow, 3).Value = Me.DOB.Value
ws.Cells(iRow, 5).Value = Me.Unit.Value
ws.Cells(iRow, 6).Value = Me.Type.Value
'clear the data
Me.Staff.Value = ""
Me.MF.Value = ""
Me.DOB.Value = ""
Me.Unit.Value = ""
Me.Type.Value = ""
Me.txtPart.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Staff_Click()
End Sub
Private Sub txtPart_Change()
End Sub
Private Sub UserForm_Click()
End Sub