Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88868

Using information information from a combinationbox in EXCEL VBA to write data to worksheet

$
0
0

I am about to make a macro controlled excel book to my son's bowling team after I saw one of the coaches trying to keep track of payments and points with paper and pencil during a competition we organized. I have come a long way but have been stuck on a thing I do not find any good solution for. In the form you write in Name, HPC [handicap], payment, payment method, player group, club and which city.

All players are registered in the same database located on the worksheet DataBas with name, HPC club .. .. .. but then the players must also be registered on other wotksheets where each player group is on a separate worksheet. When registering, you select a player group in a combination box. The idea is to use the information for registration, but I can get stuck.

Option Explicit

Sub Reset()
    Dim iRow As Integer

    iRow = [counta(DataBas!A:A)] 'Find last row in column A

     With frmform

        'Reset the form

        .txtHPC.Value = ""
        .txtName.Value = ""
        .optJa.Value = False
        .optNej.Value = False
        .ChbKontant.Value = False
        .ChbSwish.Value = False


        .cmbGrupp.Clear 'rensa kombintionsrutan

        ' Lägg till val i kombinationsrutan
        .cmbGrupp.AddItem "Småttingen"
        .cmbGrupp.AddItem "Lillinget"
        .cmbGrupp.AddItem "Mellingen"
        .cmbGrupp.AddItem "Storingen"
        .cmbGrupp.AddItem "Elit"

        .txtKlubb.Value = ""
        .txtOrt.Value = ""

        .lstDataBas.ColumnCount = 10
        .lstDataBas.ColumnHeads = True
        .lstDataBas.ColumnWidths = "25;75;50;25;60;60;30;45;70;70"

           If iRow > 1 Then
               .lstDataBas.RowSource = "DataBas!A2:J"& iRow

           Else
               .lstDataBas.RowSource = "DataBas!A2:J2"
            End If
    End With
End Sub

Sub Submit()
    Dim sh As Worksheet
    Dim iRow As Long
    Dim gRow As Long
    Dim name As String

    name = frmform.cmbGrupp.Value

    Set sh = ThisWorkbook.Sheets("DataBas")
    iRow = [counta(DataBas!A:A)] + 1 ' finding the last row and adding 1

    With sh
        .Cells(iRow, 1) = iRow - 1
        .Cells(iRow, 2) = frmform.txtName.Value
        .Cells(iRow, 3) = frmform.cmbGrupp.Value
        .Cells(iRow, 4) = frmform.txtHPC.Value
        .Cells(iRow, 7) = IIf(frmform.optNej = True, "Nej", "Ja")
        .Cells(iRow, 8) = IIf(frmform.ChbSwish = True, "Swish", "Kontant")
        .Cells(iRow, 5) = frmform.txtKlubb.Value
        .Cells(iRow, 6) = frmform.txtOrt.Value
        .Cells(iRow, 9) = Application.UserName
        .Cells(iRow, 10) = [Text(now(), "YYYY-MM-DD HH:MM:SS")]
    End With
    Set sh = ThisWorkbook.Sheets(frmform.cmbGrupp.Value)

    gRow = [counta(name! A:A)] + 1  ' ***here I'm stuck***


    Debug.Print gRow
    With sh
        .Cells(gRow, 1) = frmform.txtName.Value
        .Cells(gRow, 2) = frmform.txtHPC.Value
        .Cells(gRow, 3) = frmform.txtKlubb.Value
    End With


End Sub

Sub Show_form()

    frmform.Show

End Sub

Viewing all articles
Browse latest Browse all 88868


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>