如果单元格为空,则复制“a”行列中的下 14 个相邻单元格

问题描述 投票:0回答:1

我正在尝试选择 A 行中与 C 行中的空白单元格相邻的前 14 个

Public Sub filterBlanks()

With ActiveSheet.UsedRange

    .AutoFilter Field:=2, Criteria1:="="

    .Columns(1).SpecialCells(xlCellTypeVisible).Select

End With

End Sub

我已经走到这一步了,但无法选择第一个出现的下一个空白的 14 个,希望得到任何帮助。

我正在尝试创建一个宏,它可以复制“A”行中出现在“C”行空白单元格旁边的前 14 个相邻数字。

excel vba
1个回答
0
投票

我发现如果以后有人有问题请联系我

子副本编号() 调暗 wsSource 作为工作表 调暗 wbTarget 作为工作簿 调暗空白作为范围 调暗目标范围 昏暗我只要

' Set the source worksheet
Set wsSource = ActiveSheet

' Open the target workbook
Set wbTarget = Workbooks.Open("I:\My Drive\gs1 number my numbers - test.xlsx")

' Find the first blank cell in column C of the target workbook
For i = 1 To wbTarget.Sheets(1).Cells(wbTarget.Sheets(1).Rows.Count, "C").End(xlUp).Row
    If IsEmpty(wbTarget.Sheets(1).Cells(i, "C")) Then
        Set rngBlank = wbTarget.Sheets(1).Cells(i, "C")
        Exit For
    End If
Next i

' Check if a blank cell was found
If rngBlank Is Nothing Then
    MsgBox "No blank cell found in column C of the target workbook.", vbExclamation
    Exit Sub
End If

' Copy the corresponding cell and the 13 cells below from column A of the target workbook
Set rngTarget = wbTarget.Sheets(1).Range(wbTarget.Sheets(1).Cells(rngBlank.Row, "A"), wbTarget.Sheets(1).Cells(rngBlank.Row + 13, "A"))

' Paste the copied values to cell E5:E18 of the active worksheet
wsSource.Range("E5").Resize(14, 1).Value = rngTarget.Value

结束子

© www.soinside.com 2019 - 2024. All rights reserved.