Deleting all columns except columns with certain headings

后端 未结 3 1300
醉酒成梦
醉酒成梦 2020-12-30 13:11

I am trying to format exported data and need to delete several columns. I want to keep columns with certain headings. For convenience if I have 15 columns and want to keep c

3条回答
  •  生来不讨喜
    2020-12-30 14:13

    I had a similar problem and this is the code that worked for me. I think it is much simpler.

    Range("A1").Select
    
    Do Until ActiveCell.Value = ""
    
        If ActiveCell.Value = "Forecast Status" _
            Or ActiveCell.Value = "Amount " _
            Or ActiveCell.Value = "Service Booking Value " _
            Or ActiveCell.Value = "Transaction Number" _
            Or ActiveCell.Value = "Last Modified by" _
            Or ActiveCell.Value = "Last Modified Date" _
            Or ActiveCell.Value = "T# Comparison" _
            Or ActiveCell.Value = "Amount Comparison" _
            Or ActiveCell.Value = "Forecast Status Comparison" _
            Or ActiveCell.Value = "First Ship Date Comparison" Then
    
            ActiveCell.Offset(0, 1).Select
    
        Else
    
            ActiveCell.EntireColumn.Select
            Selection.Delete Shift:=xlToLeft
            Selection.End(xlUp).Select
    
        End If
    Loop
    

提交回复
热议问题