在Win7中的VBA中调用EXCEL 2010中的Sub()错误 [英] error of calling a Sub() in EXCEL 2010 in VBA on Win7

查看:196
本文介绍了在Win7中的VBA中调用EXCEL 2010中的Sub()错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从WEXCEL 2010 VBAon win7中调用一个子。

  find_max rng1:= rng // error !!! ByRef argument mismatch 

Sub find_max(ByRef rng1 As Range)

Dim dblM As Double
dblM = -9E + 307
Dim maxCellAddress As String
每个单元格在rng
如果IsNumeric(c)然后
如果dblMax< CDbl(Cell.Value)和Cell.Value 然后
dblM = CDbl(Cell.Value)
maxCellAddress =(Cell.Address)
End If
End If
Next Cell
End Sub

任何帮助都会欣赏!

解决方案

总结所有评论尝试这样:

  Option Explicit 

子测试()
Dim rng As Range
设置rng =范围(A1:B10)

调用find_max(rng)
End Sub

Sub find_max(rng1 As Range)
Dim dblM As Double
dblM = -9E + 307

Dim maxCellAddress As String
Dim cell作为范围

对于每个单元格在rng1
如果IsNumeric(单元格)然后
如果dblM< CDbl(cell.Value)和cell.Value<> 然后
dblM = CDbl(cell.Value)
maxCellAddress =(cell.Address)
End If
End If
下一个单元格

MsgBox(maxCellAddress)
End Sub






如果要返回最大单元格值,将其更改为如下功能:

  Option Explicit 

子测试()
Dim rng As Range
设置rng =范围(A1:B10)

MsgBox(find_max(rng))
结束Sub

函数find_max(rng1 As Range)
Dim dblM As Double
dblM = -9E + 307

Dim maxCellAddress As String
Dim cell As Range

对于每个单元格在rng1
如果IsNumeric(单元格)然后
如果dblM< CDbl(cell.Value)和cell.Value<> 然后
dblM = CDbl(cell.Value)
maxCellAddress =(cell.Address)
End If
End If
下一个单元格

find_max = maxCellAddress
结束函数


i need to call a sub from WEXCEL 2010 VBAon win7.

find_max rng1:=rng  // error !!! ByRef argu mismatch 

Sub find_max(ByRef rng1 As Range)

 Dim dblM As Double
 dblM = -9E+307
 Dim maxCellAddress As String
 For Each Cell In rng
 If IsNumeric(c) Then
       If dblMax < CDbl(Cell.Value) And Cell.Value <> "" Then
           dblM = CDbl(Cell.Value)
           maxCellAddress = (Cell.Address)
       End If
 End If
 Next Cell
 End Sub

Any help would be appreciate !

解决方案

To summarize all of the comments try this:

Option Explicit

Sub test()
    Dim rng As Range
    Set rng = Range("A1:B10")

    Call find_max(rng)
End Sub

Sub find_max(rng1 As Range)
    Dim dblM As Double
    dblM = -9E+307

    Dim maxCellAddress As String
    Dim cell As Range

    For Each cell In rng1
       If IsNumeric(cell) Then
             If dblM < CDbl(cell.Value) And cell.Value <> "" Then
                 dblM = CDbl(cell.Value)
                 maxCellAddress = (cell.Address)
             End If
       End If
    Next cell

    MsgBox (maxCellAddress)
End Sub


If you want to return the max cell value change it to a function like this:

Option Explicit

Sub test()
    Dim rng As Range
    Set rng = Range("A1:B10")

    MsgBox (find_max(rng))
End Sub

Function find_max(rng1 As Range)
    Dim dblM As Double
    dblM = -9E+307

    Dim maxCellAddress As String
    Dim cell As Range

    For Each cell In rng1
       If IsNumeric(cell) Then
             If dblM < CDbl(cell.Value) And cell.Value <> "" Then
                 dblM = CDbl(cell.Value)
                 maxCellAddress = (cell.Address)
             End If
       End If
    Next cell

    find_max = maxCellAddress
End Function

这篇关于在Win7中的VBA中调用EXCEL 2010中的Sub()错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆