Vba 如果满足单独列中的两个条件,则复制上面的单元格

Vba 如果满足单独列中的两个条件,则复制上面的单元格,vba,excel,Vba,Excel,如果E中的单元格为空且AJ不是空的,则查找VBA以复制上面(E列)的单元格。目前,这是复制上面的单元格,但没有考虑AJ列。我对VBA还比较陌生,不知道我哪里出了问题。非常感谢您的任何意见 Sub CopyFIN() 'copies FIN from account above if E is empty and AJ is anything other than empty Dim lr As Long Dim rcell As Range Dim col As Range Applicat

如果E中的单元格为空且AJ不是空的,则查找VBA以复制上面(E列)的单元格。目前,这是复制上面的单元格,但没有考虑AJ列。我对VBA还比较陌生,不知道我哪里出了问题。非常感谢您的任何意见

Sub CopyFIN() 'copies FIN from account above if E is empty and AJ is anything other than empty

Dim lr As Long
Dim rcell As Range
Dim col As Range

Application.ScreenUpdating = False

lr = Cells(Rows.Count, 6).End(xlUp).Row
Set col = Range("E12:E" & lr)
Set col2 = Range("AJ12:AJ" & lr)

    For Each rcell In col2
        If rcell.Value <> "" Then
        End If
    Next

    For Each rcell In col
        If rcell.Value = "" Then
            rcell.Offset(-1, 0).Copy rcell
        End If
    Next

Application.ScreenUpdating = True

End Sub
Sub CopyFIN()'在E为空且AJ不是空的情况下从上面的帐户复制FIN
变暗lr为长
变暗rcell As范围
暗列作为范围
Application.ScreenUpdating=False
lr=单元格(Rows.Count,6).结束(xlUp).行
设置列=范围(“E12:E”和lr)
设置col2=范围(“AJ12:AJ”和lr)
对于col2中的每个rcell
如果rcell.Value为“”,则
如果结束
下一个
每个rcell在col中
如果rcell.Value=”“,则
rcell.Offset(-1,0)。复制rcell
如果结束
下一个
Application.ScreenUpdating=True
端接头

试试这个。第一个循环没有做任何事情,第二个循环只检查E列

Sub CopyFIN() 'copies FIN from account above if E is empty and AJ is anything other than empty

Dim lr As Long
Dim rcell As Range
Dim col As Range

Application.ScreenUpdating = False

lr = Cells(Rows.Count, 6).End(xlUp).Row
Set col = Range("E12:E" & lr)

For Each rcell In col
    If Len(rcell) = 0 And Len(Cells(rcell.Row, "AJ")) > 0 Then
        rcell.Offset(-1, 0).Copy rcell
    End If
Next

Application.ScreenUpdating = True

End Sub

很好,非常感谢!现在我得去弄清楚“Len”了再次谢谢!我的荣幸。检查Len(gth)等于零相当于检查单元格是否为空。