简体   繁体   English

循环遍历范围 - 联合

[英]Looping through Ranges - Union

I am getting an error while trying to loop through my ranges.. "Method 'Union' of '_Global' failure".我在尝试遍历我的范围时遇到错误..“'_Global' 失败的方法 'Union'”。 Please someone help...After the update code I got, "Unable to get the Union property of the Application class"请有人帮忙...在我得到更新代码后,“无法获取应用程序类的联合属性”

    Dim chuteRG As Range, stowRG As Range, pickRG As Range, shipdockRG As Range, allRG As Range
    Dim cell As Range

    Set chuteRG = shChuteBowler.Range("F4:S18")
    Set stowRG = shStowBowler.Range("F4:S14")
    Set pickRG = shPickBowler.Range("F4:S12")
    Set shipdockRG = shShipDockBowler.Range("F4:S17")
    Set allRG = Union(chuteRG, stowRG, pickRG, shipdockRG).Cells

    For Each cell In allRG
        If cell = "0" Then
            cell = "X"
        End If
    Next cell


UPDATED - Still not working

    Dim chuteRG As Range, stowRG As Range, pickRG As Range, shipdockRG As Range, allRG As Range
    Dim cell As Range
    Dim ApXL As Object

    Set ApXL = CreateObject("Excel.Application")
    Set chuteRG = shChuteBowler.Range("F4:S18")
    Set stowRG = shStowBowler.Range("F4:S14")
    Set pickRG = shPickBowler.Range("F4:S12")
    Set shipdockRG = shShipDockBowler.Range("F4:S17")

    Set allRG = ApXL.Union(chuteRG, stowRG, pickRG, shipdockRG).Cells

    For Each cell In allRG
        If cell = "0" Then
            cell = "X"
        End If
    Next cell

This should do the trick.这应该可以解决问题。 You need to add ApXL.您需要添加ApXL. before calling Union .在致电Union之前。

Dim chuteRG As Range, stowRG As Range, pickRG As Range, shipdockRG As Range, allRG As Range
Dim cell As Range

Set chuteRG = shChuteBowler.Range("F4:S18")
Set stowRG = shStowBowler.Range("F4:S14")
Set pickRG = shPickBowler.Range("F4:S12")
Set shipdockRG = shShipDockBowler.Range("F4:S17")

Set allRG = ApXL.Union(chuteRG, stowRG, pickRG, shipdockRG).Cells 'AMENDED

For Each cell In allRG
    If cell = "0" Then
        cell = "X"
    End If
Next cell

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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