Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Entering data into excel 2

Status
Not open for further replies.

kha0s

Programmer
Jan 15, 2004
9
US
Heyas all,

I'm completely new to the Visual Basic scene, however I do have extensive experience in programm C/C++/ and I'm ok with C#.

My question is, How would I go about taking data entered into a form I made from the textbox and inserting it into a specified cell?

Any information would be greatly appreciated.

Thanks all!
Kha0s
 
Hi kha0s,

this is the way i use,and i'm only a novice

Range("A1") = userform1.textbox1.value

hope this getts you started

Mike
 
Kha0s,

Mike is correct,but ther's LOTS of ways to skin a cat. Using A1 notation is NOT a method that I often use.

Rather Cells(row, col) as the range object
Code:
SomeSheet.Cells(1, 1).Value =  userform1.textbox1.value
The ActiveSheet can be assumed as the Parent Object of the range, but I prefer to explicitly express.

:)

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
Great! thanks for the info. I think I may have worded my question wrong though. I need for the information to be entered into the next "available" cell in the column. Is this possible?
 
Ok, I do sheet1.Cells(2, 0) When hit '.' I don't get the Methods list, so I assume it can't take a method, I enter the whole line and it fails. What does the xldown represent?
 
I'm almost positive it's going to be on the left side, since I don't know what the xldown value should be. And that was a typo, I actually have Cells(2, 1)
 
this code
Code:
SomeSheet.Cells(1, 1).end(xldown).offset(1,0).value
starts with the cell reference and then proceeds DOWN (like [END]+[DOWN ARROW]) to the last contiguous cell and then offsets 1 row to the first EMPTY cell.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
kha0s/Skip, pardon me butting in on this one, but I literally just posted this in answer to a Q in the MS groups, and it may help kha0s understand one way of how to determine the next row (I'll butt out again now :-> )

This routine sets references to each of two sheets, Data1 where the data will be
copied from and Data2 where it will be copied to.

The lrow = wks2.Cells(Rows.Count, "A").End(xlUp).Row bit starts at
cells(rows.count, "A") on Data2 which will be Cells(65536, "A") which is the
same as A65536 and then uses End(xlUp) to work upwards and find the first cell
with data in it. The .row bit returns the row number of that cell. The last
bit of the sub then simply copies rng1 which is your range to copy each time,
and then pastes it to range(A lrow) (ie A2, A3, A4, A5... etc). The lrow + 1
bit means that it paste to the cell that is one cell down from the current last
row. This gets recalculated every time you hit the button, so will increment by
one each time.

By the way, the .Copy wks2.Cells(lrow + 1, &quot;A&quot;) bit takes the form <copy destination>



Sub CopyData()

Dim wks1 As Worksheet
Dim wks2 As Worksheet
Dim rng1 As Range
Dim lrow As Long

Set wks1 = Sheets(&quot;Data1&quot;)
Set wks2 = Sheets(&quot;Data2&quot;)
Set rng1 = wks1.Range(&quot;A1:E1&quot;)

lrow = wks2.Cells(Rows.Count, &quot;A&quot;).End(xlUp).Row

With rng1
.Copy wks2.Cells(lrow + 1, &quot;A&quot;)
End With

End Sub



----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]

----------------------------------------------------------------------------
 
ok I've narrowed the problem down to it being Ends(xlDown)

everything works fine even if I do Sheet1.Cells(2,1).Offset(1,0) and soon as I throw Ends(xlDown) in before Offset, I get &quot;Object doesn't support this property or method&quot;
 
ok I'm official retarded, it IS working. end(xlDown) <> ends(xldown)

Thanks guys!! :D
 
By the way - Just be careful about using xlDown if you could have any gaps in your data. It will stop at the first blank. May be better to start at the bottom and work up.

Regards
Ken............

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]

----------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top