Как появиться в правом столбце? - PullRequest
0 голосов
/ 11 октября 2018

У меня проблема с данными, которые не отображаются в столбце.Только первые данные.Данные имени должны появиться в столбце 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...