如何在 VB excel 2003 中迭代 MIN/MAX 函数中的单元格?

发布于 2024-12-22 14:23:17 字数 342 浏览 3 评论 0原文

    Set min=min1=1000, max=max1=position=0   
    For i=2 to 10 do 
    min=**MIN(A(i,j):A(i+5,j));**  
    if position=0 then min1=min, position=1 else  
    For j=2 to 10 do  {max=**MAX(A(i,j):A(i+5,j));**  
    if max<min then next j else position=0, next i 

我对此很陌生,并尝试在 VB excel 中执行上面的下一个代码(问题以粗体显示):谢谢

    Set min=min1=1000, max=max1=position=0   
    For i=2 to 10 do 
    min=**MIN(A(i,j):A(i+5,j));**  
    if position=0 then min1=min, position=1 else  
    For j=2 to 10 do  {max=**MAX(A(i,j):A(i+5,j));**  
    if max<min then next j else position=0, next i 

I am new at this and trying to do next code above in VB excel(problem is bolded):Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖阳 2024-12-29 14:23:18

纠正所有代码是不可能的,因为不清楚您要做什么。但以下内容可能会给您一个开始。

最好声明变量并指定它们的类型:

Dim i As Integer
Dim j As Integer
Dim max As Integer
Dim max1 As Integer
Dim min As Integer
Dim min1 As Integer
Dim Position As Integer

我更喜欢按字母顺序声明它们,但这不是必需的。

你需要:

  min = 1000
  min1 = 1000
  max = 0
  max1 = 0
  Position = 0

Set min=min1=1000, max=max1=position=0存在以下错误:

  • Set仅用于对象。
  • 不能用逗号分隔语句。
  • 在某些语言中 min=min1=1000 表示 min1=1000, min=min1 但在 VBA 中表示:

    如果 min1=1000 那么
      最小=真
    别的
      分钟=假
    结束如果 
    

没有 Do 位于 For 语句末尾。所以:

    For i = 2 To 10

MIN 和 MAX 是工作表函数。要在 VBA 中使用 then,您必须说它们是工作表函数。 VBA 中的语句末尾没有分号。您已在 MIN 函数中使用 j,但尚未设置其值。

我无法告诉 MIN 和 MAX 参数值的位置。

如果该位置位于当前工作表中,您需要类似:

With ActiveSheet
  min = Application.WorksheetFunction.min(.Range("B16:F16"))
End With

或可能类似:

With ActiveSheet
  min = Application.WorksheetFunction.min(.Range(.Cells(i,j),.Cells(i+5,j)))
End With

可以在数组上使用 MIN 和 MAX 函数,但我不知道如何选择数组的一部分。

希望这能给您一个开始。

It is impossible to correct all your code because it is not clear what you are trying to do. But the following might give you a start.

It is always best to declare your variables and to specify their type:

Dim i As Integer
Dim j As Integer
Dim max As Integer
Dim max1 As Integer
Dim min As Integer
Dim min1 As Integer
Dim Position As Integer

I prefer to declare them in alphabetic order but that is not a requirement.

You need:

  min = 1000
  min1 = 1000
  max = 0
  max1 = 0
  Position = 0

There are the following mistakes in Set min=min1=1000, max=max1=position=0:

  • Set is only used for objects.
  • You cannot separate statements by commas.
  • In some languages min=min1=1000 means min1=1000, min=min1 but in VBA it means:

    If min1=1000 Then
      min=True
    Else
      min=False
    End if 
    

There is no Do at the end of a For statement. So:

    For i = 2 To 10

MIN and MAX are worksheet functions. To use then in VBA you have to say they are worksheet functions. There are no semicolons at the end of statements in VBA. You have used j in the MIN function but have not set its value yet.

I cannot tell the location of the values that are parameters to MIN and MAX.

If the location is in the current worksheet you need something like:

With ActiveSheet
  min = Application.WorksheetFunction.min(.Range("B16:F16"))
End With

or perhaps like:

With ActiveSheet
  min = Application.WorksheetFunction.min(.Range(.Cells(i,j),.Cells(i+5,j)))
End With

It is possible, to use the MIN and MAX functions on an array but I know of no way of selecting a portion of an array.

Hope this gives you a start.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文