Link to home
Start Free TrialLog in
Avatar of Irazor
IrazorFlag for United Kingdom of Great Britain and Northern Ireland

asked on

'VB Excel 2002 using Visual Basic to add new rows with a user form and then calculate cell values'

Hi,
I've been working my way through a book and have got to a user form section. I realize that I might be able to use something like it at work.

I've created a user form that adds a new row at the bottom of the sheet. In column D I would like to add the numeric values together and give the answer in the very bottom cell of that column.
Also to have a English pound sign.
Not all the columns input will be numeric it might have the letters TBI.

I'll add the spreadsheet t ee in a moment. Also I'll add the code snippet which is pretty much out of the book I've just added another column.

Private Sub btn_EmpOK_Click()
Dim LastRow As Long
Dim FinalRow As Long
Dim i As Integer
LastRow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row + 1
Selection.Insert Shift:=xlDown
Cells(LastRow, 1).Value = tb_EmpName.Value
Cells(LastRow, 2).Value = tb_EmpPosition.Value
Cells(LastRow, 3).Value = tb_EmpHireDate.Value
Cells(LastRow, 4).Value = tb_count.Value
 
End Sub

Open in new window

Avatar of Irazor
Irazor
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Avatar of Irazor

ASKER

Oops, I didn't mean to leave in the line

Selection.Insert Shift:=xlDown

That needs to be taken out.
Avatar of Jeroen Rosink
perhaps this macro helps you out.
Made sure that the date is formated correctly and the currency value

I hope this works for you
regards,
Jeroen
Private Sub btn_EmpOK_Click()
Dim LastRow As Long
Dim FinalRow As Long
Dim i As Integer
LastRow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row + 1
Selection.Insert Shift:=xlDown
Cells(LastRow, 1).Value = tb_EmpName.Value
Cells(LastRow, 2).Value = tb_EmpPosition.Value
Cells(LastRow, 3).Value = Format(tb_EmpHireDate.Value, "MM/DD/YYYY")
Cells(LastRow, 4).Value = Format(tb_count.Value, "[$£-809]#,##0.00")
 
End Sub

Open in new window

Sorry forgot to remove the Selection.Insert line also.
Avatar of Irazor

ASKER

Hi roos01,
Thx for taking an interest. Actually this doesn't work on the spreadsheet I provided. I'm talking about the formatting that you've added. Also don't forget that I wanted it give the value of column D.

Quote:
I would like to add the numeric values together and give the answer in the very bottom cell of that column.

Did you try it in the spreadsheet I provided? And did it work for you?
ASKER CERTIFIED SOLUTION
Avatar of Jeroen Rosink
Jeroen Rosink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Irazor

ASKER

Thx for taking the time to get me this solution.
Glad to help,
thanks for the grade!
Jeroen