仅使用偶数列创建范围 [英] Creating a range with only the even number col

查看:43
本文介绍了仅使用偶数列创建范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣让 rng 仅选择偶数列(在第12列至9999之间).我在下面附上了我的代码.请协助,谢谢!

I am interested to have rng select only even columns (within Col 12 to 9999). I have attached my code below. Please assist, thank you!

Sub calDailyGC()
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Set w = Application.WorksheetFunction
    Dim gc As Double

    numGC = Cells(46, 7).Value
    numDays = Cells(47, 7).Value

    For k = 3 To numDays + 1
        Rng = Range(Cells(k, 12), Cells(k, 9999))
        sumRate = 0
        For j = 1 To numGC
            gc = Application.WorksheetFunction.Large(Rng, j)
            Debug.Print gc
            sumRate = sumRate + gc
        Next j
    Next k
    avgGCRate = sumRate / numGC

End Sub

推荐答案

尝试使用此方法代替 Rng = Range(Cells(k,12),Cells(k,9999)):

With ThisWorkbook.ActiveSheet
    Dim Rng As Range
    Dim i As Long
    i = 12
    Set Rng = .Cells(k, i)
    i = i + 2
    Do While i < 9999
        Set Rng = Union(Rng, .Cells(k, i))
        i = i + 2
    Loop
End With

这篇关于仅使用偶数列创建范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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