Excel宏 - 值比较
问题描述:
我实际上需要思考过程和选项的帮助,而不是真正的编码。Excel宏 - 值比较
我希望用户输入他们的邮政编码。然后,我需要查看邮政编码的范围。 编辑:因为我来自Belgium,邮编是4号长(1000,1500,8380,...)
Zip code: 2800
Range between;
1000-1999
2000-2999
3000-3999
4000-4999
If the range is between one of the following, display all zip codes for that range
Else do nothing
,我想出了一个如果,否则结构。但我想知道是否有更好的选择?
Zip code: 2800
If zip code > 3999 then
'Select all zipcodes within this range
'Range(" .. ").Copy Destination:=Sheets...
ElsIf zip code > 2999 then
'Select all zipcodes within this range
'Range(" .. ").Copy Destination:=Sheets...
Elsif zipcode ....
谢谢。
@@@@@@@@@@@@@
Openshac
我想出这个。
x = 1
Sheets("Reference").Select
For i = 1 to 115
If Range("A" & i).value > 5999 and Range("A" & i).value < 6000 then
Range("A" & i).copy Destination:=Sheets("Design").Range("A" & x)
x = x + 1
End if
Next i
答
switch语句怎么样?
Select Case zipCode
Case 1000 To 1999
'Do something
Case 2000 To 2999
'Do something
Case 3000 To 3999
'Do something
Case 4000 To 4999
'Do something
Case Else
' Do nothing
End Select
你有什么是好的,它只是对什么是最可读的,以你的情况下/你最容易维护。你不应该注意到任何性能差异
答
阅读各种评论我还不清楚是什么问题。我侦察你提供一个输入邮政编码(ARG = 2800),并要显示一个数据表中的所有ZIP探头在千位在千位输入的匹配,换句话说
ZIPdata.ZIP BETWEEN INT(ARG/1000) * 1000 AND INT(ARG/1000) * 1000 + 999
没有任何VBA你可以定义基于上述公式计算出的绕圈高级过滤器,该绕圈公式将是
=AND(B9>=$B$2;B9<=$E$2)
B9 being the ZIP in your first data record (not the heading)
B2 being the lower bound using above formulae
E2 being the upper bound using above formulae
或者,也可以跨ZIP和饲料洛韦限定自动过滤和上装订成经由VBA自动筛选标准。
什么是“做点什么”?每个邮政编码范围都会改变吗? – shahkalpesh 2011-04-07 08:21:35
等一下,我会改变它。 – CustomX 2011-04-07 08:27:57
hmmmm其中(Integer ??)数大于(>)5999,同时小于( MikeD 2011-04-07 11:58:57