简体   繁体   English

Excel VBA Loop在多个范围上

[英]Excel VBA Loop on multiple ranges

Hi im looking for some help on a loop i've been trying to work out. 您好,即时通讯正在寻找一些帮助,我一直在尝试解决。 Its only for a football prediction spreadsheet. 它仅适用于足球预测电子表格。

Basically i have rows of peoples name where the guess the result and the score. 基本上我有一排人的名字,猜测结果和分数。

then i have the first 2 rows as the actual result and score. 然后我将前2行作为实际结果和得分。

I've created a function to calculate it but i need to loop through each row in ranges to add up the totals. 我创建了一个函数来计算它,但是我需要遍历范围中的每一行以求和。

 `ResultRange = Range("B2", Range("A2").End(xlDown)).Rows.Count
 ScoreRange = Range("C2", Range("C2").End(xlDown)).Rows.Count
 GuessResRange = Range("D2", Range("D2").End(xlDown)).Rows.Count
 GuessScoreRange = Range("E2", Range("E2").End(xlDown)).Rows.Count

Range("B14").Value = ScorePoints(InResultRows, InScoreRows,      InGuessResult, InGuessScore)

This is what I have so far. 到目前为止,这就是我所拥有的。

Basically for 10 games ResultRows, ScoreRows, GuessResult, GuessScore 基本上用于10个游戏ResultRows,ScoreRows,GuessResult,GuessScore

would go from B2,C2,D2,E2 to B3,C3,D3,E3 and so on until it hits the end of the scores. 会从B2,C2,D2,E2变为B3,C3,D3,E3,依此类推,直到达到总分为止。 Then the total would be tallied up in Range B14. 然后将总数计入范围B14。 Then continuing this onto the next player? 然后继续到下一个播放器上吗?

Still a bit unclear about what you're trying to do, but this might get you started: 仍然不清楚您要做什么,但这可能会让您入门:

Sub FootballPredict()

    Dim GuessResRange As Range
    Dim rngLoop As Range
    Dim dblSum As Double

    Set GuessResRange = Range("B2", Range("B2").End(xlDown))

'    For Each rngLoop In GuessResRange
'        'could use this loop to do something
'    Next rngLoop

    dblSum = WorksheetFunction.Sum(GuessResRange)
    Range("B14").Value = dblSum

End Sub

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

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