Vba 删除删除线单元格并遍历所有图纸

Vba 删除删除线单元格并遍历所有图纸,vba,excel,Vba,Excel,我试图从工作簿中删除所有带删除线的单元格,并同时在所有工作表上进行迭代 我遵循了,并提出了两个宏,但它们不起作用。这是我第一次使用VBA,所以我不知道如何解决这些问题 Sub DeleteCells() Dim Cell As Range, iCh As Integer, NewText As String Dim WS_Count As Integer Dim I As Integer ' Set WS_Count equal to the number

我试图从工作簿中删除所有带删除线的单元格,并同时在所有工作表上进行迭代

我遵循了,并提出了两个宏,但它们不起作用。这是我第一次使用VBA,所以我不知道如何解决这些问题

Sub DeleteCells()
Dim Cell As Range, iCh As Integer, NewText As String
Dim WS_Count As Integer
         Dim I As Integer

         ' Set WS_Count equal to the number of worksheets in the active
         ' workbook.
         WS_Count = ActiveWorkbook.Worksheets.Count

         ' Begin the loop.
         For I = 1 To WS_Count

With Sheets(I) ' <~~ avoid select as much as possible, work directly with the objects

    Lrow = .Cells(.Rows.Count, "C").End(xlUp).Row
    For Each Cell In .Range("C1:M" & Lrow)
        For iCh = 1 To Len(Cell)
             With Cell.Characters(iCh, 1)
                 If .Font.Strikethrough = False Then NewText = NewText & .Text
            End With
        Next iCh
        Cell.Value = NewText ' <~~ You were doing it the other way around
        NewText = "" ' <~~ reset it for the next iteration
        Cell.Characters.Font.Strikethrough = False
    Next Cell
End With
Next I
End Sub
子删除单元格()
Dim单元格作为范围,iCh作为整数,NewText作为字符串
Dim WS_计数为整数
作为整数的Dim I
'将WS_Count设置为活动工作表中的工作表数
'工作簿。
WS\u Count=ActiveWorkbook.Worksheets.Count
'开始循环。
对于I=1到WS\u计数
对于纸张(I)“试试这个

Sub DeleteCells()
    Dim cel As Range
    Dim ws As Worksheet
    Dim lastRow As Long

    For Each ws In ActiveWorkbook.Worksheets    'loop through all sheets
        With ws
            lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row    'get last row with data using Column C
            For Each cel In .Range("C1:M" & lastRow)    'loop through all cells in range
                If cel.Font.Strikethrough Then          'check if cell has strikethrough property
                    cel.Clear                           'make cell blank and remove strikethrough property
                End If
            Next cel
        End With
    Next ws
End Sub
Sub DeleteCells()
    Dim cel As Range
    Dim ws As Worksheet
    Dim lastRow As Long

    For Each ws In ActiveWorkbook.Worksheets    'loop through all sheets
        With ws
            lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row    'get last row with data using Column C
            For Each cel In .Range("C1:M" & lastRow)    'loop through all cells in range
                If cel.Font.Strikethrough Then          'check if cell has strikethrough property
                    cel.Clear                           'make cell blank and remove strikethrough property
                End If
            Next cel
        End With
    Next ws
End Sub