#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Form

i am trying to set up a user form where a first name and last name are
entered. The first name must be inserted under column a and last name under
column b.

Here is the code that i am using:

Private Sub CommandButton1_Click()

Dim ans As String
Dim time As String

Sheets("sheet1").Activate
ans = Application.WorksheetFunction.CountA(Range("a:a")) + 1
Cells(ans, 1) = TextBox1.Text
TextBox1.Text = ""

time = Application.WorksheetFunction.Count(Range("b:b")) + 2
Cells(time, 1) = TextBox2.Text
TextBox2.Text = ""


End Sub

This throws both under column a
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Form

Hi Darren,
Make a fix In line
Cells(time, 1) = TextBox2.Text

to
Cells(time, 2) = TextBox2.Text


Regards,
Stefi

€˛Darren€¯ ezt Ć*rta:

i am trying to set up a user form where a first name and last name are
entered. The first name must be inserted under column a and last name under
column b.

Here is the code that i am using:

Private Sub CommandButton1_Click()

Dim ans As String
Dim time As String

Sheets("sheet1").Activate
ans = Application.WorksheetFunction.CountA(Range("a:a")) + 1
Cells(ans, 1) = TextBox1.Text
TextBox1.Text = ""

time = Application.WorksheetFunction.Count(Range("b:b")) + 2
Cells(time, 1) = TextBox2.Text
TextBox2.Text = ""


End Sub

This throws both under column a

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Form

Hi Darren,

Try:

'=============
Private Sub CommandButton1_Click()
Dim rng1 As Range
Dim rng2 As Range

With Sheets("Sheet1") '<<==== CHANGE
Set rng1 = .Cells(Rows.Count, "A").End(xlUp)(2)
Set rng2 = .Cells(Rows.Count, "B").End(xlUp)(2)
End With

rng1.Value = Me.TextBox1.Value
rng2.Value = Me.TextBox2.Value

End Sub
'<<=============


---
Regards,
Norman



"Darren" wrote in message
...
i am trying to set up a user form where a first name and last name are
entered. The first name must be inserted under column a and last name
under
column b.

Here is the code that i am using:

Private Sub CommandButton1_Click()

Dim ans As String
Dim time As String

Sheets("sheet1").Activate
ans = Application.WorksheetFunction.CountA(Range("a:a")) + 1
Cells(ans, 1) = TextBox1.Text
TextBox1.Text = ""

time = Application.WorksheetFunction.Count(Range("b:b")) + 2
Cells(time, 1) = TextBox2.Text
TextBox2.Text = ""


End Sub

This throws both under column a



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass variable from form to form to form headly Excel Programming 1 May 31st 06 02:50 AM
Strange issue freezing parent form when unloading a child form Stefano Gatto Excel Programming 1 November 11th 05 04:42 PM
how can I make a form number change everytime the form is opened babydumplingspita Excel Worksheet Functions 1 October 10th 05 07:58 PM
form in excel to be attached to the emails address in the form upon sumission Abdulkader Bhanpurawala via OfficeKB.com Excel Programming 6 July 10th 05 10:48 AM
Is it possible to open the VBA form with a link in a sheet and to pass variable from a cell to the VBA form? Daniel[_14_] Excel Programming 1 August 29th 04 01:20 PM


All times are GMT +1. The time now is 01:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"