Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel Q:归档后如何清除单元格?_Excel_Archiving_Vba - Fatal编程技术网

Excel Q:归档后如何清除单元格?

Excel Q:归档后如何清除单元格?,excel,archiving,vba,Excel,Archiving,Vba,我把一个宏放在一起,它允许我将数据从一张纸归档到另一张纸,但是我在事后清除信息时遇到了困难。第一列包含我不想清除的数字,现在它只清除B列中的数据 如果有人能看看这个,我会非常高兴的 'Sub archive() Dim i, lastrow Dim mytext As String lastrow = Sheets("Rooms").Range("A" & Rows.Count).End(xlUp).Row For i = 1 To lastrow mytext = Sheets("Ro

我把一个宏放在一起,它允许我将数据从一张纸归档到另一张纸,但是我在事后清除信息时遇到了困难。第一列包含我不想清除的数字,现在它只清除B列中的数据

如果有人能看看这个,我会非常高兴的

'Sub archive()
Dim i, lastrow
Dim mytext As String
lastrow = Sheets("Rooms").Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lastrow
mytext = Sheets("Rooms").Cells(i, "F").Text
If InStr(mytext, "yes") Then
Sheets("Rooms").Cells(i, "A").EntireRow.Copy Destination:=Sheets("Archive").Range("A" & Rows.Count).End(xlUp).Offset(1)
Sheets("Rooms").Cells(i, "B").Clear
End If
Next i
End Sub'

我在B列中的关联行上获取了该单元格,并将其扩展到同一行中包含任何值的最后一个单元格

Sub archive()
    Dim i, lastrow
    Dim mytext As String

    With WorkSheets("Rooms")
        lastrow = .Range("A" & Rows.Count).End(xlUp).Row
        For i = 1 To lastrow
            mytext = .Cells(i, "F").Text
            If InStr(1, mytext, "yes", vbTextCompare) Then
                .Cells(i, "A").EntireRow.Copy Destination:=Sheets("Archive").Range("A" & Rows.Count).End(xlUp).Offset(1)
                .Range(.Cells(i, "B"), .Cells(i, Columns.Count).End(xlToLeft)).Clear
            End If
        Next i
    End With
End Sub
此外,我还使用了一个将
工作表(“房间”)
与其所有单元格关联起来,以避免重复引用工作表

该命令将清除所有值和格式。如果只希望删除这些值,则可能需要切换到