[英]Vba Cell Selection Based on Value
我什么都沒問我在找什么...
我使用兩種條件來設置選擇(找到值“ Reducer”,然后在其正下方的單元格中找到“” {一個空單元格))。
我無法找到一種方法來選擇符合這些條件的單元格,然后列出該單元格的地址(我想在消息框中顯示該單元格的地址,向他們警告“錯誤”的位置)
最終將有更多的單元格要尋找,這就是為什么我要搜索多個單元格。
簡而言之,我希望我的代碼找到兩個條件,選擇符合條件的單元格,並顯示一條彈出消息,指出錯誤所在的單元格。
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Range("J11").Value < 0 Then
MsgBox "You have exceeded the maximum allowable pipe length for this section. Please review your selection before continuing. ", vbOKOnly, "Inoperable Pipe Length"
End If
Do While ActiveSheet.Range("J17,J7").Value = "Reducer"
If ActiveSheet.Range("J18,J8").Value = "" Then
G = Sheets("Pipe Calcs").Range("J18,J8").Address
MsgBox "Please Select a reducer size in cell " & G & ActiveCell.Address(False, False), vbCritical, "No Reducer Size Selected"
Exit Sub
Else
End
End If
Loop
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If ActiveSheet.Range("A1").Value < 0 Then
MsgBox "You have exceeded the maximum allowable pipe length for this section. Please review your selection before continuing. ", vbOKOnly, "Inoperable Pipe Length"
End If
For Each cell In Range("J1:J1000")
If cell.Value = "Reducer" Then
If Range(cell.Address).Offset(1, 0) = "" Then
G = Sheets("Pipe Calcs").Range(cell.Address).Offset(1, 0).Address
MsgBox "Please Select a reducer size in cell " & G
Range(Cell.Address).Offset(1, 0).Select
Exit Sub
End If
End If
Next
End Sub
上面的代碼將檢查J
列中的“ Reducer”,如果找到,它將查看下面的單元格是否包含一個值,如果沒有,它將提示用戶輸入該單元格並退出子項。 當用戶更新單元格時,他們觸發Worksheet_Change
語句並導致宏再次運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.