我有一个用于输入翻译的用户表单。有用于标题 (txtTitle)、要翻译的文本 (txtToTranslate) 和已翻译文本 (txtTranslation) 的文本框以及用于选择语言的组合框 (cboLanguage)。
当前,每次用户单击提交时,代码都会创建一个新的数据行。我想修改功能如下:
1 点击提交,检查A:A中是否已经存在txtTitle
2a 如果 txtTitle 不存在,则创建新行(当前功能)
2b 如果 txtTitle 存在,将 txtTranslation 添加到带有 txtTitle 的行,而不是“NextRow”
Private Sub btnSubmit_Click()
Dim FindString As String
Dim Rng As Range
FindString = "*" & txtTitle
If Trim(FindString) & "*" <> "" Then
With Sheets("output").Range("A:A")
Set Rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
????
Else
Sheets("output").Activate
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
Cells(NextRow, 1) = txtTitle.Text
Cells(NextRow, 2) = txtToTranslate.Text
If cboLanguage = "fr-FR" Then Cells(NextRow, 3) = txtTranslation.Text
If cboLanguage = "it-IT" Then Cells(NextRow, 4) = txtTranslation.Text
If cboLanguage = "de-DE" Then Cells(NextRow, 5) = txtTranslation.Text
Unload frmNewTranslation
End If
End With
End If
End Sub