View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Clear some columns but not all columns and keep headers in all columns

Hi Howard,

Am Tue, 4 Jul 2017 14:29:22 -0700 (PDT) schrieb L. Howard:

Using this select case only as a means to explain what I want some code to do. Actual code to be whatever is most efficient.

Case has the column Header and the column letter is not part of the header name, I put it in there for reference only, real header name is like... Answer Sports?

Case Else are the target columns to clear, keeping header for ALL columns.


try:

Sub ClearColumns()
Dim LRow As Long
Dim myStr As String
Dim i As Integer

myStr = "Answer Movie?,Answer Art?,Answer Sports?,Answer Geography?,Answer Math?"

With Sheets("Sheet3")
LRow = .UsedRange.Rows.Count
For i = 1 To 15
If InStr(myStr, .Cells(1, i)) = 0 Then
.Range(.Cells(2, i), .Cells(LRow, i)).ClearContents
End If
Next
End With
End Sub


Regards
Claus B.
--
Windows10
Office 2016