Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Clear some columns but not all columns and keep headers in all columns

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.

Thanks,
Howard

From column A to column O on Sheet3...

Select Case columnHeading
Case "Answer Movie? C", "Answer Sports? F", "Answer Geography?
I", "Answer Math? L", "Answer Art? O"
'Do nothing
Case Else
'ClearContents in columns (A B D E G H J K M N) row 2 on down to variable end
End Select
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Clear some columns but not all columns and keep headers in all columns

On Tuesday, July 4, 2017 at 3:04:34 PM UTC-7, Claus Busch wrote:
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.
--


Hi Claus,

The columns in MyStr are the columns I want to remain untouched. All the other columns cleared.

The columns are sequenced in this manner

Name Movie "Answer Movie?" Name Sports "Answer Sports?" etc. etc.

Five columns are named "Name" and five are the category (Movie, Sports etc.) and five are Answer xx? columns.

All the Answer xxx? column to remain intact with formulas in them.

I tried adjusting the code but the InStr was picking up Movie and Answer Movie as an example.

Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Clear some columns but not all columns and keep headers in all columns

On Tuesday, July 4, 2017 at 5:38:14 PM UTC-7, L. Howard wrote:
On Tuesday, July 4, 2017 at 3:04:34 PM UTC-7, Claus Busch wrote:
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.
--


Hi Claus,

The columns in MyStr are the columns I want to remain untouched. All the other columns cleared.

The columns are sequenced in this manner

Name Movie "Answer Movie?" Name Sports "Answer Sports?" etc. etc.

Five columns are named "Name" and five are the category (Movie, Sports etc.) and five are Answer xx? columns.

All the Answer xxx? column to remain intact with formulas in them.

I tried adjusting the code but the InStr was picking up Movie and Answer Movie as an example.

Howard


Hi Claus,

I was able to make it work with this.
Thanks for help getting me there.

Howard

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

myStr = "Name, Movie, Sports, Geography, Math, Art"

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
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 21:02:25 -0700 (PDT) schrieb L. Howard:

I was able to make it work with this.
Thanks for help getting me there.


sorry that I misunderstood your problem.

Try:

Sub ClearCols()
Dim LRow As Long
Dim i As Integer

With Sheets("Sheet3")
LRow = .UsedRange.Rows.Count
For i = 3 To 15 Step 3
.Range(.Cells(2, i), .Cells(LRow, i)).ClearContents
Next
End With
End Sub


Regards
Claus B.
--
Windows10
Office 2016
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make headers for columns in which their are 6 columns? jobo Excel Worksheet Functions 3 January 16th 10 06:32 PM
How do I slant the headers of the columns? Filly Excel Worksheet Functions 2 April 15th 08 06:41 PM
Line up headers and columns Georgea Excel Discussion (Misc queries) 0 January 6th 08 07:00 PM
Clear columns or Drap Columns Display 007[_2_] Excel Programming 0 July 22nd 06 06:40 PM
copy over just columns and headers lbierer Setting up and Configuration of Excel 1 July 14th 06 08:52 PM


All times are GMT +1. The time now is 02:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"