Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default fresh learner need help!

I began to study VBA just from yesterday. I strike in a program from
the book, the code is like this:

[code]:

Private Sub CommandButton1_Click()
Range("D8").Select
Selection.End(xlDown).Select
Selection.End(xlToLeft).Select

ActiveCell.Offset(1, 0).Range("A1") = TextBox1.Text
ActiveCell.Offset(1, 0).Range("B1") = TextBox2.Text
ActiveCell.Offset(1, 0).Range("C1") = TextBox3.Text
ActiveCell.Offset(1, 0).Range("D1") = TextBox4.Text
ActiveCell.Offset(1, 0).Range("E1") = TextBox5.Text


End Sub

Private Sub CommandButton2_Click()
End
End Sub

Private Sub CommandButton3_Click()
TextBox1.Text = "88"
TextBox2.Text = "Michael"
TextBox3.Text = "123455"
TextBox4.Text = "1322"
TextBox5.Text = "Record for test"
End Sub

when I try to run it. it reports an error: Run time error '1004'
application-defined or object-defined error . When I debug it, it shows
something wrong with this sentence:
ActiveCell.Offset(1, 0).Range("A1") = TextBox1.Text. But after
doublecheck, I still can not find any problem. I copy it from the book
exactly.

Anybody's help is appreciated!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default fresh learner need help!

Hi Flamingo,

You would encounter this problem if there were no data below cell D8.

This is because the instruction;

Selection.End(xlDown).Select


would then select the column D cell in the last row on the sheet and, then,
the instruction:

ActiveCell.Offset(1, 0).Range("A1") = TextBox1.Text


would be seeking to address a row below the last row - which is impossible.

For your test purposes enter some data in, say, cells D8:D9 and try again.


---
Regards,
Norman



"Flamingo" wrote in message
ups.com...
I began to study VBA just from yesterday. I strike in a program from
the book, the code is like this:

[code]:

Private Sub CommandButton1_Click()
Range("D8").Select
Selection.End(xlDown).Select
Selection.End(xlToLeft).Select

ActiveCell.Offset(1, 0).Range("A1") = TextBox1.Text
ActiveCell.Offset(1, 0).Range("B1") = TextBox2.Text
ActiveCell.Offset(1, 0).Range("C1") = TextBox3.Text
ActiveCell.Offset(1, 0).Range("D1") = TextBox4.Text
ActiveCell.Offset(1, 0).Range("E1") = TextBox5.Text


End Sub

Private Sub CommandButton2_Click()
End
End Sub

Private Sub CommandButton3_Click()
TextBox1.Text = "88"
TextBox2.Text = "Michael"
TextBox3.Text = "123455"
TextBox4.Text = "1322"
TextBox5.Text = "Record for test"
End Sub

when I try to run it. it reports an error: Run time error '1004'
application-defined or object-defined error . When I debug it, it shows
something wrong with this sentence:
ActiveCell.Offset(1, 0).Range("A1") = TextBox1.Text. But after
doublecheck, I still can not find any problem. I copy it from the book
exactly.

Anybody's help is appreciated!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default fresh learner need help!

Hi Norman,

thanks a lot. it works after I modify it according to your suggestion!
You really do me a favor. Very appreciate it.

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
Hello, fresh here! HardenMassie Excel Worksheet Functions 0 August 24th 10 10:13 PM
Need a fresh pair of eyes ibvalentine Excel Worksheet Functions 11 May 3rd 09 11:33 PM
Fresh pair of Eyes required [email protected] Excel Worksheet Functions 4 March 17th 08 11:54 PM
PIVOT LEARNER - Field Entry billy_bags Excel Worksheet Functions 1 July 19th 06 01:22 PM
Just a learner...!!! Alok Garg Excel Programming 1 February 24th 05 07:36 AM


All times are GMT +1. The time now is 04:14 PM.

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

About Us

"It's about Microsoft Excel"