宏范围/特定单元格消息框
macro range / specific cells msg box
你能帮我做个微距吗?我有一个 3 代码,只有在特定值时才显示消息框。但不要为我工作。 :/我不知道为什么。一些错误,我想制作所有范围,然后在值满足时向我显示 msgbox。有人认识吗?
现在我有但显示错误请看图片
Public Sub found(worksheets)
Dim found As Boolean
Dim c As Range
found = False
For Each c In worksheets("data").Range("D155,D456,D757,D1058,D1359,D1660,D1961:D1964,D36811,D36813,D38015,D38617,D39219,D39821,D40423,D41025,D52576,D53178,D54984,D55586,D56790,D57392,D58897")
If c.Value = 8 Then
found = True
c.Value = -1
End If
Next
If found Then MsgBox (" ZAHLASTE BALENÍ !!!") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 15 KS")
found = False
For Each c In worksheets("data").Range("D29,D31,D33,D35,D37,D39,D41,D43,D45,D47,D49,D51:D57,D59,D61,D63,D65,D67:D83,D85,D87,D89,D91:D95,D97:D101,D103,D105,D107,D109,D110:D111,D41944,D42246:D42250,D45263,D45265,D45267,D45269,D45271,D45273,D45275,D45277,D45279,D45280,D45581,D45882,D46183,D46484,D46785,D47086,D47387")
If c.Value = 5 Then
found = True
c.Value = -1
End If
Next
If found Then MsgBox (" ZAHLASTE BALENÍ") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 6 KS")
found = False
For Each c In worksheets("data").Range("D3165,D3466,D3767,D4068,D4369,D4670,D4971,D5272,D5573,D5874,D6175:D10088,D10389,D10690,D41643,D41945,D42251,D42552,D42853,D43154,D43455,D43755,D44057,D44357,D44658,D44959,D48892,D49193,D49494,D49795,D50097,D50397,D50698,D50999,D51308:D51339")
If c.Value = 8 Then
found = True
c.Value = -1
End If
Next
If found Then MsgBox (" ZAHLASTE BALENÍ") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 9 KS")
End Sub
接下来sheet我打电话给Call Module1.check(worksheets)
这部分代码显示错误。
除了应用上面的注释(特别是使用 "D155"
而不是 "D155:D155"
等,
以下是如何在每个操作完成后仅显示一次消息框:
Dim found as Boolean
found = false
For Each c In worksheets("data").Range(...)
If c.Value = 8 Then
found = True
c.Value = -1
End If
Next
If found then MsgBox (" ZAHLASTE BALENÍ !!!") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 15 KS")
found = false
For Each c In worksheets("data").Range(...)
If c.Value = 5 Then
found = True
c.Value = -1
End If
Next
If found then MsgBox (" ZAHLASTE BALENÍ") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 6 KS")
found = false
For Each c In worksheets("data").Range(...)
If c.Value = 8 Then
found = True
c.Value = -1
End If
Next
If found then MsgBox (" ZAHLASTE BALENÍ") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 9 KS")
编辑:下一个问题
如果提交的字符串太长,超过 255 个字符,方法 Range
将失败。您可以通过将范围规范分为两部分来解决它:
Dim r As Range
Set r = worksheets("data").Range("D29,D31,D33,D35,D37,D39,D41,D43,D45,D47,D49,D51:D57,D59,D61,D63,D65,D67:D83,D85,D87,D89,D91:D95,D97:D101,D103,D105,D107,D109,D110:D111,D41944,D42246:D42250,D45263,D45265,D45267,D45269,D45271,D45273")
Set r = Union(r, worksheets("data").Range("D45275,D45277,D45279,D45280,D45581,D45882,D46183,D46484,D46785,D47086,D47387"))
For Each d in r ' <-- Proceed from here
你能帮我做个微距吗?我有一个 3 代码,只有在特定值时才显示消息框。但不要为我工作。 :/我不知道为什么。一些错误,我想制作所有范围,然后在值满足时向我显示 msgbox。有人认识吗?
现在我有但显示错误请看图片
Public Sub found(worksheets)
Dim found As Boolean
Dim c As Range
found = False
For Each c In worksheets("data").Range("D155,D456,D757,D1058,D1359,D1660,D1961:D1964,D36811,D36813,D38015,D38617,D39219,D39821,D40423,D41025,D52576,D53178,D54984,D55586,D56790,D57392,D58897")
If c.Value = 8 Then
found = True
c.Value = -1
End If
Next
If found Then MsgBox (" ZAHLASTE BALENÍ !!!") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 15 KS")
found = False
For Each c In worksheets("data").Range("D29,D31,D33,D35,D37,D39,D41,D43,D45,D47,D49,D51:D57,D59,D61,D63,D65,D67:D83,D85,D87,D89,D91:D95,D97:D101,D103,D105,D107,D109,D110:D111,D41944,D42246:D42250,D45263,D45265,D45267,D45269,D45271,D45273,D45275,D45277,D45279,D45280,D45581,D45882,D46183,D46484,D46785,D47086,D47387")
If c.Value = 5 Then
found = True
c.Value = -1
End If
Next
If found Then MsgBox (" ZAHLASTE BALENÍ") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 6 KS")
found = False
For Each c In worksheets("data").Range("D3165,D3466,D3767,D4068,D4369,D4670,D4971,D5272,D5573,D5874,D6175:D10088,D10389,D10690,D41643,D41945,D42251,D42552,D42853,D43154,D43455,D43755,D44057,D44357,D44658,D44959,D48892,D49193,D49494,D49795,D50097,D50397,D50698,D50999,D51308:D51339")
If c.Value = 8 Then
found = True
c.Value = -1
End If
Next
If found Then MsgBox (" ZAHLASTE BALENÍ") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 9 KS")
End Sub
接下来sheet我打电话给Call Module1.check(worksheets)
这部分代码显示错误。
除了应用上面的注释(特别是使用 "D155"
而不是 "D155:D155"
等,
以下是如何在每个操作完成后仅显示一次消息框:
Dim found as Boolean
found = false
For Each c In worksheets("data").Range(...)
If c.Value = 8 Then
found = True
c.Value = -1
End If
Next
If found then MsgBox (" ZAHLASTE BALENÍ !!!") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 15 KS")
found = false
For Each c In worksheets("data").Range(...)
If c.Value = 5 Then
found = True
c.Value = -1
End If
Next
If found then MsgBox (" ZAHLASTE BALENÍ") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 6 KS")
found = false
For Each c In worksheets("data").Range(...)
If c.Value = 8 Then
found = True
c.Value = -1
End If
Next
If found then MsgBox (" ZAHLASTE BALENÍ") & vbCrLf & ("BALÍCÍ MNOŽSTVÍ JE 9 KS")
编辑:下一个问题
如果提交的字符串太长,超过 255 个字符,方法 Range
将失败。您可以通过将范围规范分为两部分来解决它:
Dim r As Range
Set r = worksheets("data").Range("D29,D31,D33,D35,D37,D39,D41,D43,D45,D47,D49,D51:D57,D59,D61,D63,D65,D67:D83,D85,D87,D89,D91:D95,D97:D101,D103,D105,D107,D109,D110:D111,D41944,D42246:D42250,D45263,D45265,D45267,D45269,D45271,D45273")
Set r = Union(r, worksheets("data").Range("D45275,D45277,D45279,D45280,D45581,D45882,D46183,D46484,D46785,D47086,D47387"))
For Each d in r ' <-- Proceed from here