簡體   English   中英

刪除指定列 VBA

[英]Delete specified column VBA

嗨,只是想在工作簿中的每張紙上運行一個代碼。 由於某種原因,它不會刪除指定的列。 我也試過使用Columns(“A”).Delete並且這也不起作用

Sub Format()

'Firstly convert all text cells into number cells for every sheet in workbook

For Each WS In Sheets
    On Error Resume Next
    For Each r In WS.UsedRange.SpecialCells(xlCellTypeConstants)
        If IsNumeric(r) Then r.Value = (r.Value) * 1
        ''Or test the values in the next column on the right
        'If IsNumeric(r) Then r.Offset(0,1).Value = (r.Value)*1
    Next r

    Rows("1:15").Delete
    Columns(“1”).Delete


Next WS

End Sub

您沒有用工作表限定這些引用……它應該是這樣的:

WS.Rows("1:15").Delete
WS.Columns(1).Delete

如果你不這樣做,那么它只是在每次循環時假定ActiveSheet

另請注意,您沒有將列的1放在引號中。 1是索引值,而不是字符串值。

此外,您使用的引號類型是錯誤的。 仔細看:

WS.Columns(“A”).Delete  ' <--- these curly quotes will not work (they are not the same thing)

WS.Columns("A").Delete  ' <--- these straight quotes work

直引號和彎引號

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM