我有一個腳本,用於檢查工作表中的新商店。如果它找到一家新店,它應該打開一個表單並提示用戶選擇一個店鋪類別,然後點擊確定。當用戶點擊確定時,應該選擇下拉菜單中的值,然後窗體關閉並繼續循環。VBA - 在循環中打開表格,然後等待OK單擊
形式是卡列斯 「shopkat」
這是它如何工作的:
For i = LBound(distshops) To UBound(distshops)
If Not IsEmpty(distshops(i)) Then
curcell = getrows
curshop = distshops(i)
findout = checkifinsheet(curshop)
If findout = False Then
Cells(curcell + 1, 1) = curshop
'show form
shopkat.Show vbModal
'shop current shop
shopkat.shop.Caption = curshop
'Get value from combo
Cells(curcell + 1, 2) = shopkat.shopkatcombo.value
'if user click ok then continue
End If
End If
Next i
會有人幫助。非常感謝!
////////////////////////////更新///////////////// ////////////// 模塊1:
Public curcell As Long
Dim ws As Worksheet
形式shopkat:
Private Sub shopkatok_Click()
If Not shopkat.shopkatcombo.value = "" Then
ws.Cells(curcell + 1, 2) = shopkat.shopkatcombo.value
Unload Me
End If
End Sub
毛圈片(Shopcategories)
Set ws = ThisWorkbook.Sheets("Shopcategories")
For i = LBound(distshops) To UBound(distshops)
If Not IsEmpty(distshops(i)) Then
curcell = getrows()
curshop = distshops(i)
findout = checkifinsheet(curshop)
If findout = False Then
shopkat.shop.Caption = curshop
'show form
shopkat.Show
If Not IsEmpty(Cells(curcell + 1, 2).value) Then
ws.Cells(curcell + 1, 1) = curshop
End If
End If
End If
Next i
我不明白你的問題。當您以模式打開表單時,代碼的下一行將不會執行,直到表單被卸載。 –
我想我現在明白你想要什麼了......一刻 –
我已經更新了代碼。希望它更容易理解 – Tino