繁体   English   中英

基于值的Vba单元选择

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM