Problems with userform

M

Marcus Pedersén

Hi!
I use a userform to add new rows in a table but I get an error:
"User-defined type not defined" and I can not figure out the problem. I´m
using the following code and the error row is marked *.

Private Sub CommandButton1_Click()
* Dim LastRow As Object
Set LastRow = Sheet1.Range("a65536").End(xlUp)
LastRow.Offset(1, 0).Value = TextBox1.Text
LastRow.Offset(1, 1).Value = TextBox2.Text
LastRow.Offset(1, 2).Value = TextBox3.Text
MsgBox "One record written to Sheet1"
response = MsgBox("Do you want to enter another record?", _
vbYesNo)
If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox1.SetFocus
Else
Unload Me
End If
End Sub

......a second question. I want the frames around the cells with the text
that is added to be "painted" black when I click "Add to record" how do I do
that?

Many, many, many thanks in advance!!!

Marcus
 
D

Dave Peterson

One way to put a border around a range of cells is with the .borderaround
method. You can find more info/options in VBA's help:

Option Explicit
Private Sub CommandButton1_Click()
Dim LastRow As Range
Dim response As Long

Set LastRow = Sheet1.Range("a65536").End(xlUp)
LastRow.Offset(1, 0).Value = TextBox1.Text
LastRow.Offset(1, 1).Value = TextBox2.Text
LastRow.Offset(1, 2).Value = TextBox3.Text
LastRow.Offset(1, 0).Resize(1, 3).BorderAround _
LineStyle:=xlDash, Weight:=xlThick, ColorIndex:=3
MsgBox "One record written to Sheet1"
response = MsgBox("Do you want to enter another record?", _
vbYesNo)
If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox1.SetFocus
Else
Unload Me
End If
End Sub

But your code ran as-is for me. But I would define LastRow as Range.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top