We’d like to remind Forumites to please avoid political debate on the Forum.

This is to keep it a safe and useful space for MoneySaving discussions. Threads that are – or become – political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Visual Basic

I hope someone can help.

I am trying to create a Customer details form to input details into an excel spreadsheet.

I have used Visual Basic before but not for a while and I have completely forgotten how to set it up to work.

I have created the form and set up a click button to get the form up in Excel. What I am struggling with is getting the details from the form to automatically go to the next available row at the click of a button.

Can anyone help??

Comments

  • rmg1
    rmg1 Posts: 3,159 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    First, a couple of assumptions.
    1) the data is going onto a sheet named "Sheet1"
    2) there is a save button on the userform

    In the code for the save button, you'll need something like :-
    lastcell=Sheets("sheet1").range("A65536").end(xlup)
    Sheets("sheet1").Range("A" & lastcell+1)=textbox1.text
    Sheets("sheet1").Range("B" & lastcell+1)=textbox2.text
    Sheets("sheet1").Range("C" & lastcell+1)=textbox3.text
    Sheets("sheet1").Range("D" & lastcell+1)=textbox4.text
    Sheets("sheet1").Range("E" & lastcell+1)=textbox5.text
    Sheets("sheet1").Range("F" & lastcell+1)=textbox6.text
    Sheets("sheet1").Range("G" & lastcell+1)=textbox7.text
    Sheets("sheet1").Range("H" & lastcell+1)=textbox8.text
    Sheets("sheet1").Range("I" & lastcell+1)=textbox9.text
    (Expand as necessary).

    If you are using comboboxes (dropdowns), subsitute combobox(number).value for textbox(number).text
    You can change "Sheet1" for whatever the sheet name is.

    Should get you started.
    :wall: Flagellation, necrophilia and bestiality - Am I flogging a dead horse? :wall:

    Any posts are my opinion and only that. Please read at your own risk.
  • Lifeisbutadream
    Lifeisbutadream Posts: 13,102 Forumite
    rmg1 wrote: »
    First, a couple of assumptions.
    1) the data is going onto a sheet named "Sheet1"
    2) there is a save button on the userform

    In the code for the save button, you'll need something like :-
    lastcell=Sheets("sheet1").range("A65536").end(xlup)
    Sheets("sheet1").Range("A" & lastcell+1)=textbox1.text
    Sheets("sheet1").Range("B" & lastcell+1)=textbox2.text
    Sheets("sheet1").Range("C" & lastcell+1)=textbox3.text
    Sheets("sheet1").Range("D" & lastcell+1)=textbox4.text
    Sheets("sheet1").Range("E" & lastcell+1)=textbox5.text
    Sheets("sheet1").Range("F" & lastcell+1)=textbox6.text
    Sheets("sheet1").Range("G" & lastcell+1)=textbox7.text
    Sheets("sheet1").Range("H" & lastcell+1)=textbox8.text
    Sheets("sheet1").Range("I" & lastcell+1)=textbox9.text
    (Expand as necessary).

    If you are using comboboxes (dropdowns), subsitute combobox(number).value for textbox(number).text
    You can change "Sheet1" for whatever the sheet name is.

    Should get you started.


    Thank you so much.

    I used to just copy old formulas, but I have since bought a new PC and didnt transfer all my documents over.

    Very impressivly quick answer by the way!
  • rmg1
    rmg1 Posts: 3,159 Forumite
    Part of the Furniture 1,000 Posts Name Dropper
    Just nice timing, and the fact that I've literally just finished doing something similar for the bods here at work. :j
    :wall: Flagellation, necrophilia and bestiality - Am I flogging a dead horse? :wall:

    Any posts are my opinion and only that. Please read at your own risk.
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 352.5K Banking & Borrowing
  • 253.7K Reduce Debt & Boost Income
  • 454.5K Spending & Discounts
  • 245.5K Work, Benefits & Business
  • 601.5K Mortgages, Homes & Bills
  • 177.6K Life & Family
  • 259.5K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 37.7K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.