при отладке он показывает - метод или элемент данных не найден и будет выделен в .cell.Могу ли я знать, почему с этой ошибкой?
я уже меняю ячейки на ячейки.но все равно не сработало.
Я все еще новичок в VBA, я уже искал несколько веб-сайтов или любые предложения, но мне все еще трудно понять и не совсем ясно.
Любая помощьбыл бы очень признателен.
Спасибо
Private Sub cmdAdd_Click()
'dimention the variable
Dim DataSH As Worksheet
Dim Addme As Range
Dim str As String
Dim totalRows As Long
'set the variable
Set DataSH = Sheet1
'error handler
On Error GoTo errHandler:
'set variable for the destination
Set Addme = DataSH.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
'hold in memory and stop screen flicker
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
'determine worksheet row to post data
totalRows = Sheet1**.Cell**(Rows, Count, "A").End(xUp).Row
If totalRows < 3 Then
totalRows = 3
Else
totalRows = totalRows
End If
'send the values to the database
Sheet1.Cell(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, "
'deleting comma and space, the 2 characters at the end of str
str = Left(str, Len(str) - 2)
Sheet1.Cell(totalRows + 1, 2) = str
If optYes.Value = True Then
Sheet1.Cell(totalRow + 1, 3) = "Yes"
ElseIf optNo.Value = True Then
Sheet1.Cell(totalRows + 1, 3) = "No"
End If
Sheet1.Cell(totalRows + 1, 4) = cboAmount.Value
Sheet1.Cell(totalRows + 1, 5) = cboCeti.Value
Sheet1.Cell(totalRows + 1, 6) = txtPhone.Text
Sheet1.Cell(totalRows + 1, 7) = txtEmail.Text
'sort the data by "cboCeti"
DataSH.Select
With DataSH
.Range("A2:G10000").Sort Key1:=Range("E2"), Order1:=xlAscending, Header:=xlGuess
End With