Results 1 to 4 of 4

Thread: vb and excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    2

    vb and excel

    Hey.

    I have text boxes in an excel worksheet, and I want to input data into these text boxes and then click a command button which puts these text values into a new row in another worksheet. Just wondering if there are any basic ideas how I can go about doing this.

    Thanks

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: vb and excel

    Welcome to the Forums.

    Moved

    What type of textboxes are they? ActiveX or Forms textboxes?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    2

    Re: vb and excel

    forms

  4. #4
    Lively Member New2vba's Avatar
    Join Date
    Sep 2005
    Location
    UK
    Posts
    95

    Re: vb and excel

    Try this, but with specifics changed to suit your spreadsheet/requirements. The textbox and command button can be on any sheet within the workbook.

    VB Code:
    1. Private Sub CommandButton1_Click()
    2.  
    3. 'Declare your data type - note that if you set a specific data
    4. 'type such as numeric, you must trap for non-numeric entries
    5. Dim X As String
    6.  
    7. 'Set variable equal to textbox value
    8. X = TextBox1.Value
    9.  
    10. 'Add data to cell A1 of Sheet2 - you can change this to any cell
    11. 'on any sheet witin the workbook
    12. With ActiveWorkbook
    13.     Worksheets("Sheet2").Range("A1").FormulaR1C1 = X
    14. End With
    15.  
    16. 'Note that each time you click the command button, the data in cell
    17. 'A1 will be overwritten with the data in your text box
    18.  
    19. End Sub

    Hope this helps.

    EDIT:

    Just realised that you said your textboxes were forms type. This code relates to control toolbox textboxes. Are you sure you have form type textboxes in Excel? When I use forms in Excel (2003), the textbox FormField is not available.
    Last edited by New2vba; Apr 27th, 2006 at 12:02 PM.
    "Those things we must learn to do, we must learn by doing" (or hope somebody else will take pity and help out )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width