Hi, I would like to create a macro where a new row will be inserted and the fields "name", "date_joined", and "Capital" are being pulled out from a userform (the code is also in the "command_button" of the said userform.
This is quite easy. But...there are 4 other columns that contain purely formulas.
As you can see, I've tried some codes from the internet hence the commented codes but they're pretty messed up.
Also, I am running the macro from an 'index' sheet so I can't use activecell
Thanks in advance!
This is quite easy. But...there are 4 other columns that contain purely formulas.
Code:
[COLOR=#333333]<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Private Sub cmd_add_Click()
If txtname.Text = "" Or txtdate.Text = "" Or txtcapital.Text = "" Then
MsgBox "Some Fields Missing", vbOKOnly, "Error"
Else
ThisWorkbook.Sheets("Members").Activate
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Members")
R = ActiveCell.Row
'ActiveCell.Offset(1).EntireRow.Insert Shift:=xlDown
'Cells(ActiveCell.Row + 1, 2) = "=" & Cells(Active Cell.Row, 2).Address & "+1"
LastRow = ws.Range("B" & Rows.Count).End(xlUp).Row + 1
ws.Range("A" & LastRow).Value = ""
ws.Range("B" & LastRow).Value = Me.txtname.Value
ws.Range("C" & LastRow).Value = Me.txtdate.Value
ws.Range("D" & LastRow).Value = Me.txtcapital.Value
'ws.Range("E" & R + 1 & ":G" & R + 1).Formula = ws.Range("E" & R & ":G" & R).Formula
'ws.Range("E" & R & ":G" & R).Copy Destination:=ws.Range("E" & R + 1 & ":R" & R + 1)
ws.Range("E" & LastRow + 1).Value = ws.Range("E" & ActiveCell.Row).Formula
End If</code>[/COLOR]
Also, I am running the macro from an 'index' sheet so I can't use activecell
Thanks in advance!