iT邦幫忙

0

VBA 表單 限制不能輸入重複的內容

請問 我的VBA表單內怎麼做才能使 TEXTBOX 內輸入的值如果有重複
跳一個MSGBOX出來警告
我可以怎麼修改 我的VBA目前是這樣

Private Sub CB1_Click()
    
 Dim Rng As Range
 Set Rng = Range("B1:B1000").Find(TB2, lookat:=xlPart)
 
    
 If Rng Is Nothing Then
    MsgBox "無此車位"

Else

r = Rng.Row
Cells(r, "A") = TB1.Text
Cells(r, "C") = CBB1.Text
Cells(r, "D") = TB3.Text
Cells(r, "E") = CBB2.Text
Cells(r, "F") = TB4.Text
Cells(r, "G") = CBB3.Text
Cells(r, "H") = TB5.Text

Cells(r, "B").Select

TB1.Text = ""
CBB1.Text = ""
TB2.Text = ""
CBB2.Text = ""
TB3.Text = ""
CBB3.Text = ""
TB4.Text = ""
TB5.Text = ""




End If

End Sub
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
海綿寶寶
iT邦大神 1 級 ‧ 2020-04-28 16:13:05
最佳解答

我看不懂你要做什麼
參考看看有沒有用

Sub Macro1()
    If Cells(3, 3) = "Text" Then
        MsgBox "有重覆資料", vbInformation
    End If
    If Cells(3, 3) = TB1.Text Then
        MsgBox "有重覆資料", vbInformation
    End If
    If TB1.Text = "999" Then
        MsgBox "有重覆資料", vbInformation
    End If
    If TB1.Text = TB2.Text Then
        MsgBox "有重覆資料", vbInformation
    End If
End Sub
九號 iT邦新手 5 級 ‧ 2020-04-28 16:19:56 檢舉

你好 我是想要 在我的TB2裡面輸入的值
不跟 Range("B1:B1000")內重複..
若有重複 MSGBOX出來阻擋 這樣

你不是拿 TB2 去 Range("B1:B1000") Find 了嗎?
如果沒 FIND 到--->表示沒重複
如果有 FIND 到--->重複, 顯示 msgbox
這樣可以嗎?

九號 iT邦新手 5 級 ‧ 2020-04-29 10:38:38 檢舉

恩恩 成功了
這個EXCEL VBA功能我改了三天 結果主管說
他手動輸入 跟 篩選搜尋就好了 傻眼哈哈哈
不過還是謝謝你 學到很多

我要發表回答

立即登入回答