Jump to content
Do Not Sell My Personal Information


  • Join Toyota Owners Club

    Join Europe's Largest Toyota Community! It's FREE!

     

     

Visual Basic Help In Excel


S.Kayani
 Share

Recommended Posts

Hi guys, bit of a long shot but - i was wondering if you guys could help me, im making a project at college where i have to make a system on excel

and i really need your help!!!

basically i need to know a code for an OK button for a userform so that when data is entered into a user form, it gets added to the next row in the list on a spreadsheet - the current code i have is

Range(col_Pos + "A34") = NewProductsForm.TextBox1.Value

Range(col_Pos + "B34") = NewProductsForm.TextBox2.Value

as you can see when ok is pressed the data will go to A34 and B34

basically i need to know a code so that the next time data is entered it will go to the next free row, e.g A35 and B35 then A36 then B36 etc - onwards... (if the cells above are in use)

hope you understand what i mean!!

and thanks ALOT!!

Link to comment
Share on other sites

what does col_Pos do?

Can you do it so you can add a string and a integer together?

eg.

Range(A + int);

This way all you have to do is int = int + 1

Not done visual basic in absolutely ages so dont know what you can do with it

Link to comment
Share on other sites

I'm not a VBA expert, but col_Pos looks like a variable

Why not store the data in an array, then simply add the new data at the next free location

Link to comment
Share on other sites

cheers ill try that, think it stands for column position

any other ideas?

Link to comment
Share on other sites

It a bit difficult to say without seeing the full code

do you have something like

"Dim Col_pos As Long"

It could stand for column position, depends on who originally wrote the code, I dont see any comments

Link to comment
Share on other sites


thanks alot for your replys guys!! seriously appreciate it!! this needs to be handed in tomorrow so i need to get this working so i can get some of the other stuff done

12911455148.jpg

this screen shows the form and where the information should go, basically i need a code so that when ok is clicked the new data wont just go to cell A34 and B34 next time something it added i need it to go to the next free cells

and heres a print screen of the original code

12911455145.jpg

Link to comment
Share on other sites

the easiest way is something like this ........

Set a counter out of the way and +1 to it every time an item is added.

( it would be helpful to declare this as a variable rather than just reading the range. it'll make things a whole lot easier. We'll call this variable Roger for this example ! )

Then, instead of saying

Range(col_Pos + "A34") = NewProductsForm.TextBox1.Value

Range(col_Pos + "B34") = NewProductsForm.TextBox2.Value

use the code A&Roger instead of A34, B&Roger instead of B34.

on the CommandButton1.click subroutine add a line saying Roger = Roger+1

it's a basic way of doing it ( no pun intended ), but perfectly acceptable.

Good luck !"

Rich

Don't forget !

Declare Roger as a public variable and you can stash the counter anywhere on any form !

Link to comment
Share on other sites

thanks alot for your help matey!!

managed to get it sorted!

the code used was

Private Sub CommandButton1_Click()

Dim LastRow As Long

If WorksheetFunction.CountA(Cells) > 0 Then

'Search for any entry, by searching backwards by Rows.

LastRow = Cells.Find(What:="*", After:=[A1], _

SearchOrder:=xlByRows, _

SearchDirection:=xlPrevious).Row

LastRow = LastRow + 1

End If

Range("A" & LastRow) = NewProductsForm.TextBox1.Value

Range("B" & LastRow) = NewProductsForm.TextBox2.Value

NewProductsForm.Hide

Unload Me

End Sub

Link to comment
Share on other sites

Latest Deals

Toyota Official Store for genuine Toyota parts & accessories

Disclaimer: As the club is an eBay Partner, The club may be compensated if you make a purchase via eBay links

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share







×
×
  • Create New...




Forums


News


Membership


  • Insurance
  • Support