iT邦幫忙

0

VBA表單填寫數值完偶爾無法正常往下一欄,而直接覆蓋原本欄位???

https://ithelp.ithome.com.tw/upload/images/20210425/20136917wSs9TEsEew.png
https://ithelp.ithome.com.tw/upload/images/20210425/20136917iBDbSYGXXr.png
正常添寫完數據後會自動往下一欄,然後再重複著個動作。但是偶爾會出現沒有自動往下一欄格,而覆蓋掉原本欄位。

這個是點餐的公式
Private Sub NewB_Click()

ActiveSheet.Unprotect

LF = Range("J4").End(xlDown).Row + 1

Cells(LF, 10) = NText.Text
Cells(LF, 11) = CText.Text
Cells(LF, 12) = RText.Text
Cells(LF, 13) = MText.Text
Cells(LF, 14) = MtText.Text
Cells(LF, 15) = PText.Text
Cells(LF, 16) = OText.Text
Cells(LF, 9).Select
結帳Text.Text = Cells(LF, 17)

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True

NText.Text = " "
CText.Text = " "
RText.Text = " "
MText.Text = " "
MtText.Text = " "
PText.Text = " "
OText.Text = " "

End Sub

這個是庫存的公式

Private Sub NewB_Click()

ActiveSheet.Unprotect

LF = Range("C4").End(xlDown).Row + 1

Cells(LF, 3) = 奶油Text.Text
Cells(LF, 4) = 紅豆Text.Text
Cells(LF, 5) = 麻糬Text.Text
Cells(LF, 6) = 芋泥Text.Text
Cells(LF, 7) = 馬鈴薯Text.Text
Cells(LF, 8) = OREOText.Text

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFormattingCells:=True

奶油Text.Text = " "
紅豆Text.Text = " "
麻糬Text.Text = " "
芋泥Text.Text = " "
馬鈴薯Text.Text = " "
OREOText.Text = " "
End Sub

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

2 個回答

1
小魚
iT邦大師 1 級 ‧ 2021-04-25 08:00:18

你把欄位都遮住了,
還問甚麼 XD
不過我上次看過你的畫面,
大概知道是甚麼問題.
所以你要先看懂它在寫甚麼啊 XD

話說...為什麼你的兩個函式名稱一樣?
不會呼叫錯嗎?
如果沒呼叫錯的話,
你是用J(上面那個)或C(下面那個)來判斷要處理哪一列,
所以你要確認這兩欄最下面一定有資料,
否則就會出現你說的情況.

另外,
建議一下,
要貼程式碼最好貼文字,
然後上下用`包起來,
如果有人要幫忙測是比較方便.

teachterv iT邦新手 5 級 ‧ 2021-04-26 00:22:29 檢舉

謝謝您的提醒

1
海綿寶寶
iT邦大神 1 級 ‧ 2021-04-25 14:23:13

1.在 VBA 裡設定中斷點
2.(點 NewB_Click)執行停下來後,按 F8 一列一列執行就可以找出原因

teachterv iT邦新手 5 級 ‧ 2021-04-26 00:31:30 檢舉

因為我也是上網抓教學影片依樣畫葫蘆,我自己就算抓出來也沒辦法自己解決問題

解鈴還須繫鈴人
你還是去問教學影片的作者
可能會比較快

我要發表回答

立即登入回答