How can I input data to excel from inputting data in text box where the text box are from two or more Userform Using Excel VB?

user3292755

I am trying to ease the data entry from financial report, so i try to make forms using Excel Visual Basic.

I made 2 Userform so far ,later i will made 5. I made userform so the data entry operator can have simple design of the form, because the textboxs are so many,then I partitioned the sector into 5 userform to simplifiy it.

To move between Sector, the operator can jump to another userform using command button.

When the operator has finished the data entry from all 3 userform, he will comeback to the main Userform to Entry the data all at once into excel.

My problem is, i find it difficult to connect between userform to take the value from each userform so that finally the value can be inputted to excel all at once using 1 command button at the main userform or userform1.

My code for the command button is this:

Private Sub cmdAddData_Click()
 'Copy input values to sheet.
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Summary")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
    .Cells(lRow, 1).Value = Me.txtNo.Value
    .Cells(lRow, 2).Value = Me.txtKode.Value
    .Cells(lRow, 3).Value = Me.txtNamaPerusahaan.Value
    .Cells(lRow, 4).Value = Me.txtSector.Value
    .Cells(lRow, 5).Value = Me.txtTime.Value
    'UserForm2Begin'
    .Cells(lRow, 7).Value = Me.txtKas.Value
    .Cells(lRow, 8).Value = Me.txtInvestasi.Value
    .Cells(lRow, 9).Value = Me.txtDanaTerbatas.Value
    .Cells(lRow, 10).Value = Me.txtPiutangUsaha.Value
    'UserForm2End'
  End With

'Clear input controls.
Me.txtNo.Value = ""
Me.txtKode.Value = ""
Me.txtNamaPerusahaan.Value = ""
Me.txtSector.Value = ""
Me.txtTime.Value = ""
'Userform2Begin'
Me.txtKas.Value = ""
Me.txtInvestasi.Value = ""
Me.txtDanaTerbatas.Value = ""
Me.txtPiutangUsaha.Value = ""
'Userform2End'

Thanks in advance

lsteinme

If you declare every textfield that you want to read from public you can do it like this:

 Class MainForm
    Form firstPage
    Form secondPage
    ...

    Private Sub cmdAddData_Click()
     'Copy input values to sheet.
    Dim lRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Summary")
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    With ws
        .Cells(lRow, 1).Value = firstPage.txtNo.Value
        .Cells(lRow, 2).Value = firstPage.txtKode.Value
        .Cells(lRow, 3).Value = firstPage.txtNamaPerusahaan.Value
        .Cells(lRow, 4).Value = firstPage.txtSector.Value
        .Cells(lRow, 5).Value = firstPage.txtTime.Value
        'UserForm2Begin'
        .Cells(lRow, 7).Value = secondPage.txtKas.Value
        .Cells(lRow, 8).Value = secondPage.txtInvestasi.Value
        .Cells(lRow, 9).Value = secondPage.txtDanaTerbatas.Value
        .Cells(lRow, 10).Value = secondPage.txtPiutangUsaha.Value
        'UserForm2End'
      End With

    'Clear input controls.
    Me.txtNo.Value = ""
    Me.txtKode.Value = ""
    Me.txtNamaPerusahaan.Value = ""

    firstPage.txtSector.Value = ""
    firstPage.txtTime.Value = ""
    'Userform2Begin'
    secondPage.txtKas.Value = ""
    secondPage.txtInvestasi.Value = ""
    secondPage.txtDanaTerbatas.Value = ""
    secondPage.txtPiutangUsaha.Value = ""

End Sub



End Class

As mentioned if you want to use this approach, you need to set the visibility to public (in the graphical editor its the attribute Modifiers)

The better solution would be you declare an object in the Mainfrom that has attributes for all values you want to have in you Excel file later. Then give this object to every form, for example in the constructor, and fill it. In you Mainform you can then read all attributes form the object and write them to the file. The Object for holding you data would somthing like this:

    Class DataObject
        Public txtNo as String
        Public txtKode as String
        ...
    End Class

You declare it in the first Form that the user can see and then give it to every form that follows

Class FirstForm
   Dim data as DataObject
   ...

   private sub openNextWindow()
       dim sec as SecondForm= new SecondForm(DataObject)
       ...
   end sub
end class

Until you finally are at your cmdAddData where you do it like this:

Private Sub cmdAddData_Click()
     'Copy input values to sheet.
    Dim lRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Summary")
    lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    With ws
        .Cells(lRow, 1).Value = data.txtNo
        .Cells(lRow, 2).Value = data.txtKode
        ...      
End Sub

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

how to concatenate two or more text box values in one text box

분류에서Dev

how to select from database and populate in a text box on Vb. net

분류에서Dev

esporting data from userform of vba excel to mysql

분류에서Dev

sending input from text box to controller

분류에서Dev

Text box data getting cleared, when I click on check box

분류에서Dev

how to save data by disabled text box?

분류에서Dev

Vb.net Two Times togeather HH : MM from to the text box

분류에서Dev

How can I automate inputting text into a prompt?

분류에서Dev

How to get more than one value of text box using in condition

분류에서Dev

How do I access the text in a text box from a button click event handler

분류에서Dev

Extract data from a very messy text file into Excel

분류에서Dev

Importing data from text file and saving the same in excel

분류에서Dev

can not add text box input in table

분류에서Dev

How can I add a comment in word in a text box?

분류에서Dev

Using find() in Excel to remove text from string

분류에서Dev

Showing data in DataGridView based on specific text box

분류에서Dev

How should I save string from the Radio Button in arraylist and display it on next page in text box

분류에서Dev

how can i get my local DB data to fill my txt box using LINQ?

분류에서Dev

regex for text box to validate input

분류에서Dev

Can I use SQL to build an Excel data table from other Excel files?

분류에서Dev

Get the value of clicked text box from array of text boxes using PHP

분류에서Dev

How can I create a message box from the command line?

분류에서Dev

Data extraction from a text file using bash

분류에서Dev

Microsoft Access Insert Into Statement Selecting Data from Excel --- Field is Mixed Int and Text

분류에서Dev

How to make form input box larger in HTML (along with text)?

분류에서Dev

Excel: Using text from a cell as the name of a worksheet in a conditional formatting equation

분류에서Dev

How to copy specific data after check box is selected in VBA Excel 2010?

분류에서Dev

choose a name from drop down list or if not exit, can write in text box

분류에서Dev

How to concatenate two values into text box in c#?

Related 관련 기사

  1. 1

    how to concatenate two or more text box values in one text box

  2. 2

    how to select from database and populate in a text box on Vb. net

  3. 3

    esporting data from userform of vba excel to mysql

  4. 4

    sending input from text box to controller

  5. 5

    Text box data getting cleared, when I click on check box

  6. 6

    how to save data by disabled text box?

  7. 7

    Vb.net Two Times togeather HH : MM from to the text box

  8. 8

    How can I automate inputting text into a prompt?

  9. 9

    How to get more than one value of text box using in condition

  10. 10

    How do I access the text in a text box from a button click event handler

  11. 11

    Extract data from a very messy text file into Excel

  12. 12

    Importing data from text file and saving the same in excel

  13. 13

    can not add text box input in table

  14. 14

    How can I add a comment in word in a text box?

  15. 15

    Using find() in Excel to remove text from string

  16. 16

    Showing data in DataGridView based on specific text box

  17. 17

    How should I save string from the Radio Button in arraylist and display it on next page in text box

  18. 18

    how can i get my local DB data to fill my txt box using LINQ?

  19. 19

    regex for text box to validate input

  20. 20

    Can I use SQL to build an Excel data table from other Excel files?

  21. 21

    Get the value of clicked text box from array of text boxes using PHP

  22. 22

    How can I create a message box from the command line?

  23. 23

    Data extraction from a text file using bash

  24. 24

    Microsoft Access Insert Into Statement Selecting Data from Excel --- Field is Mixed Int and Text

  25. 25

    How to make form input box larger in HTML (along with text)?

  26. 26

    Excel: Using text from a cell as the name of a worksheet in a conditional formatting equation

  27. 27

    How to copy specific data after check box is selected in VBA Excel 2010?

  28. 28

    choose a name from drop down list or if not exit, can write in text box

  29. 29

    How to concatenate two values into text box in c#?

뜨겁다태그

보관