Excel VBA代码。如何循环一列,找到介于0.9和1之间的值,然后将这些值向左偏移4行? Set ColumnE=工作表(“电话簿”)。范围(“E:E”) 模糊的名字一样长 在这本书中,我们将写下即将迎来生日的人的名字。 对于列中的每个rng 如果(rng.Value>=0.9且rng.Value

Excel VBA代码。如何循环一列,找到介于0.9和1之间的值,然后将这些值向左偏移4行? Set ColumnE=工作表(“电话簿”)。范围(“E:E”) 模糊的名字一样长 在这本书中,我们将写下即将迎来生日的人的名字。 对于列中的每个rng 如果(rng.Value>=0.9且rng.Value,excel,vba,Excel,Vba,使用Offset在单元格周围导航 Set ColumnE = Worksheets("Phonebook").Range("E:E") Dim Names As Long 'In this we will write the names of the people who have upcoming birthdays. For Each rng In ColumnE If (rng.Value >= 0.9 And rng.Value <= 1) Then End

使用
Offset
在单元格周围导航

Set ColumnE = Worksheets("Phonebook").Range("E:E")
Dim Names As Long
'In this we will write the names of the people who have upcoming birthdays.
For Each rng In ColumnE
    If (rng.Value >= 0.9 And rng.Value <= 1) Then

    End If
Next
MsgBox " " & Names & " has an upcoming birthday."
选项显式
子测试()
将ws设置为工作表:设置ws=ThisWorkbook.Sheets(“电话簿”)
Dim LRow为长,MyCell为范围,名称为字符串
LRow=ws.Range(“E”&ws.Rows.Count).End(xlUp).Row
对于ws.范围内的每个迈塞尔(“E2:E”和LRow)

如果MyCell>=0.9并且MyCell
将theNames作为字符串进行调暗…theNames=theNames&IIf(len(theNames)>0,vbLf,“”)&rng.offset(0,-4).Value
@TimWilliams是的!这完全符合我的需要!非常感谢!我爱你!
Option Explicit

Sub Test()

Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Phonebook")
Dim LRow As Long, MyCell As Range, Names As String
LRow = ws.Range("E" & ws.Rows.Count).End(xlUp).Row

For Each MyCell In ws.Range("E2:E" & LRow)
    If MyCell >= 0.9 And MyCell <= 1 Then
        Names = MyCell.Offset(, -4) & ", " & Names
    End If
Next MyCell

Names = Left(Names, Len(Names) - 2)

If Len(Names) Then
    MsgBox Names & " has an upcoming birthday!"
Else
    MsgBox "No upcoming birthdays."
End If

End Sub