Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

How do I specify a range for a do loop in Excel VBA

I'm tying to write an If statement within a Do loop stating: If the value in column B is "X" and the max value of range B-M is < 5 Then...

But I can't seem to figure out how to tell it the range. The do loop ends at the end of the list

This part of the code doesn't work:

If Worksheets("Sheet1").Range(i - 3, 2) = "Fen" and Worksheets("Sheet1").Range(.cells(i - 3, 2), i - 3, 10)Then

    'Set i to equal first row
    i = 7
    Do
    
    'Pull values from another tab using formulas
    .Cells(i + 1, 2).Formula = "= 'Pasted Feature Information'!A" & i - 4
    .Cells(i + 1, 1).Formula = "= 'Pasted Feature Information'!B" & i - 4
    

    
    If Worksheets("Sheet1").Range(i - 3, 2) = "Fen" And Worksheets("Sheet1").Range(.Cells(i - 3, 2), .Cells(i - 3, 10)) < 5 Then
    .Cells(7, 5) = "Range"
    
    
    
    
   
    .Cells(i + 1, 3).Formula = "=IFERROR(IF(AND(B" & i + 1 & "=""fen"", MAX('Results Drawdown'!C" & i - 2 & ":M" & i - 2 & ")> INDEX(Lists!$K$3:$M$7,MATCH(B" & i + 1 & ",Lists!$K$3:$K$7,0),2)),""send to Groundwater Specialist"",IF(AND(B" & i + 1 & "=""well"", MAX('Results Drawdown'!C" & i - 2 & ":M" & i - 2 & ")> INDEX(Lists!$K$3:$M$7,MATCH(B" & i + 1 & ",Lists!$K$3:$K$7,0),2)),""send to Groundwater Specialist"","""")),"""")"
    .Cells(i + 1, 4).Formula = "=IF(AND(B" & i + 1 & "=""fen"",C" & i + 1 & "<>""""),""Drawdown was calculated at the fen"",IF(AND(B" & i + 1 & "=""well"",C" & i + 1 & "<>""""),""Drawdown in well may cause interference"",""""))"
    End If
    i = i + 1
    Loop Until Cells(i, 1).Value = 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...