从2列中获取最后一行,然后将数据input到列的1中

在发布这个问题之前,我做了一个search。 我发现的结果只是find1列的最后一行,我想find2列的最后一行,然后相应地input数据。 希望你们可以帮忙。 谢谢! 🙂

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 

这是现在的输出

在这里输入图像说明

这是用户表单的样子

这是我想要的输出

你非常接近解决scheme。 ;) 尝试这个:

 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