我在发布此问题之前进行了搜索。我找到的结果只找到1列的最后一行,我想找到2列的最后一行,然后相应地输入数据。希望你们能提供帮助。谢谢! :)
If optMemberName.Value = True Then
With Sheets("Sheet1")
Range("A" & .Cells(.Rows.Count, "A").End(xlUp).Row) = txtMemberName.Text
End With
ElseIf optMemberID.Value = True Then
With Sheets("Sheet1")
Range("B" & .Cells(.Rows.Count, "B").End(xlUp).Row) = txtMemberID.Text
End With
End If
这是现在的输出
这就是用户形式的样子
这是我想要的输出
答案 0 :(得分:0)
你非常接近解决方案。 ;)试试这个:
Private Sub CommandButton1_Click()
Dim rA As Long, rB As Long
Dim lastRow As Long
rA = Cells(Rows.Count, 1).End(xlUp).Row ' returns last row of first column
rB = Cells(Rows.Count, 2).End(xlUp).Row ' returns last row of second column
lastRow = IIf(rA > rB, rA + 1, rB + 1) ' returns maximum of rA and rA plus one
If optMemberName.Value = True Then
Cells(lastRow, 1) = txtMemberName.Text
ElseIf optMemberID.Value = True Then
Cells(lastRow, 2) = txtMemberID.Text
End If
End Sub