alokgarg47

New Member
Joined
Jan 12, 2012
Messages
7
Hey guyz, thanks for this amazing blog.
I am a newbie to visual basic and i would really appreciate if you could help me with my stupid problems...

I am creating a database for brain tumors in excel spreadsheet. So, i am using VBA Userform to add the data.
I have attached an image of the first draft (with fake data).

And the following is the code i used for the userform:


Private Sub cmdAdd_Click()
Dim iRow As Long
Dim iPart As Long
Dim ws As Worksheet
Set ws = Worksheets("Glioblastoma")

'find first empty Row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1

'check for a part number
If Trim(Me.txtName.Value) = "" Then
Me.txtName.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 2).Value = Me.txtName.Value
ws.Cells(iRow, 3).Value = Me.cboSex.Value
ws.Cells(iRow, 4).Value = Me.txtMrn.Value
ws.Cells(iRow, 5).Value = Me.txtDateofbirth.Value
ws.Cells(iRow, 6).Value = Me.txtDateofpresentation.Value
ws.Cells(iRow, 7).Value = Me.txtDateofsurgery.Value
ws.Cells(iRow, 8).Value = Me.txtSurgicalnote.Value
ws.Cells(iRow, 9).Value = Me.txtIdh.Value
ws.Cells(iRow, 10).Value = Me.txtMgmt.Value
ws.Cells(iRow, 11).Value = Me.txtTp53.Value
ws.Cells(iRow, 12).Value = Me.cboTumobank.Value
ws.Cells(iRow, 13).Value = Me.cboPresentstatus.Value
ws.Cells(iRow, 14).Value = Me.txtComments.Value

'clear the data
Me.txtName.Value = ""
Me.cboSex.Value = ""
Me.txtMrn.Value = ""
Me.txtDateofbirth.Value = ""
Me.txtDateofpresentation.Value = ""
Me.txtDateofsurgery.Value = ""
Me.txtSurgicalnote.Value = ""
Me.txtIdh.Value = ""
Me.txtMgmt.Value = ""
Me.txtTp53.Value = ""
Me.cboTumobank.Value = ""
Me.cboPresentstatus.Value = ""
Me.txtComments.Value = ""
Me.txtName.SetFocus

End Sub
Private Sub cmdClear_Click()
'clear the data
Me.txtName.Value = ""
Me.cboSex.Value = ""
Me.txtMrn.Value = ""
Me.txtDateofbirth.Value = ""
Me.txtDateofpresentation.Value = ""
Me.txtDateofsurgery.Value = ""
Me.txtSurgicalnote.Value = ""
Me.txtIdh.Value = ""
Me.txtMgmt.Value = ""
Me.txtTp53.Value = ""
Me.cboTumobank.Value = ""
Me.cboPresentstatus.Value = ""
Me.txtComments.Value = ""
Me.txtName.SetFocus

End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub


Now my problem is, I dont wanna keep an empty row in the spreadsheet. I mean, i wanna add a few more cells with some formula to calculate from the newly added data. for example, in the first column, i wanna fill up the serial numbers beforehand. Now, if i fill those data, the data would get filled up to the next empty row.

I have another query. At the end of each update, i would like to save the data alphabetically (Name column "B2"). How can i add a macro to do that?

Thanks a lot!
Any help will be appreciated
7331285.jpg
[/URL][/IMG]
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,216,177
Messages
6,129,323
Members
449,501
Latest member
Amriddin

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