如何显示在右栏中?

时间:2018-10-11 02:13:45

标签: excel vba excel-vba

我有一个问题,那就是数据没有出现在列中。仅第一个数据。名称数据应出现在B9列。

然后,名称将出现在最后一个数据的A列中。

数据将像这样出来;

enter image description here

我应该在哪里纠正错误?

我认为是在此行的错误-

ws.Cells(totalRows + 1, 1) = txtName.Text

希望任何人都可以帮助我。

先谢谢您。

Private Sub cmdAdd_Click()

Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Master Data")
Dim Addme As Range, str As String, totalRows As Long

Set Addme = ws.Cells(ws.Rows.Count, 3).End(xlUp).Offset(1, 0)

Application.ScreenUpdating = False

If Me.txtName = "" Or Me.cboAmount = "" Or Me.cboCeti = "" Then
    MsgBox "There is insufficient data, Please return and add the needed information"
    Exit Sub
End If

totalRows = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
totalRows = Application.WorksheetFunction.Max(totalRows, 3)

ws.Cells(totalRows + 1, 1) = txtName.Text

If cbWhatsapp.Value = True Then
    str = "Whatsapp, "
End If

If cbSMS.Value = True Then
    str = str & "SMS, "
End If

If cbEmail.Value = True Then
    str = str & "Email, "
End If

If cbFacebook.Value = True Then
    str = str & "Facebook, "
End If

If cbPhoneCall.Value = True Then
    str = str & "Phone Call, "
End If
str = Left(str, Len(str) - 2)
    ws.Cells(totalRows + 1, 2) = str

If optYes.Value = True Then
    ws.Cells(totalRows + 1, 3) = "Yes"
ElseIf optNo.Value = True Then
    ws.Cells(totalRows + 1, 3) = "No"
End If

ws.Cells(totalRows + 1, 4) = cboAmount.Value
ws.Cells(totalRows + 1, 5) = cboCeti.Value
ws.Cells(totalRows + 1, 6) = txtPhone.Text
ws.Cells(totalRows + 1, 7) = txtEmail.Text

ws.Range("B9:H10000").Sort Key1:=Range("F9"), Order1:=xlAscending, Header:=xlGuess

MsgBox "Your data was successfully added"

Sheet1.Select

On Error GoTo 0
Exit Sub
End Sub

0 个答案:

没有答案