使用EXCEL VBA中组合框中的信息将数据写入工作表
在我们组织的一场比赛中,我看到一位教练试图用纸和笔记录付款和积分,我正准备为我儿子的保龄球队制作一本宏观控制的excel手册。我已经走了很长一段路,但在一件我没有找到任何好的解决办法的事情上遇到了困难。 在您填写的表格中填写姓名、HPC[残疾]、付款、付款方式、球员组、俱乐部和所在城市 所有球员都注册在同一个数据库中,该数据库位于工作表数据库中,名称为HPC club。。 但是,玩家还必须在其他工作表上注册,每个玩家组都在单独的工作表上。注册时,您可以在组合框中选择一个玩家组。我的想法是使用这些信息进行注册,但我可能会被卡住使用EXCEL VBA中组合框中的信息将数据写入工作表,excel,vba,Excel,Vba,在我们组织的一场比赛中,我看到一位教练试图用纸和笔记录付款和积分,我正准备为我儿子的保龄球队制作一本宏观控制的excel手册。我已经走了很长一段路,但在一件我没有找到任何好的解决办法的事情上遇到了困难。 在您填写的表格中填写姓名、HPC[残疾]、付款、付款方式、球员组、俱乐部和所在城市 所有球员都注册在同一个数据库中,该数据库位于工作表数据库中,名称为HPC club。。 但是,玩家还必须在其他工作表上注册,每个玩家组都在单独的工作表上。注册时,您可以在组合框中选择一个玩家组。我的想法是使用这些
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
您不需要变量
名称
替换
Set sh = ThisWorkbook.Sheets(frmform.cmbGrupp.Text)
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
用这个
Dim grpsh As Worksheet
Set grpsh = ThisWorkbook.Sheets(frmform.cmbGrupp.Value)
With grpsh
Dim gRow As Long
gRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Row 'CountA is unreliable
.Cells(gRow, 1).Value = frmform.cmbGrupp.Value
.Cells(gRow, 2).Value = frmform.txtHPC.Value
.Cells(gRow, 3).Value = frmform.txtKlubb.Value
End With