Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Deleting columns based upon the value that appears in ROW A

Hi

I would like to delete columns in a spreadsheet dependant
upon the value in row a.

So for example the macro could say delete all columns
other than those that have "First Name", "Surname"
or "Score" in row a.

Is this possible ?

If so, can you tell me how to do it ?

Thanks in advance.
Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Deleting columns based upon the value that appears in ROW A

Hi
see:
http://www.xldynamic.com/source/xld.Deleting.html


-----Original Message-----
Hi

I would like to delete columns in a spreadsheet dependant
upon the value in row a.

So for example the macro could say delete all columns
other than those that have "First Name", "Surname"
or "Score" in row a.

Is this possible ?

If so, can you tell me how to do it ?

Thanks in advance.
Steve
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting columns based upon the value that appears in ROW A

Dim rng as Range, sStr as String, i as Long
set rng = cells(1,"IV").End(xltoLeft)
for i = rng.column to 1 step -1
sStr = lcase(cells(1,i).Value)
if sStr < "first name" and _
sStr < "surname" and _
sStr < "score" then
cells(1,i).EntireColumn.Delete
end if
Next

--
Regards,
Tom Ogilvy

"Steve" wrote in message
...
Hi

I would like to delete columns in a spreadsheet dependant
upon the value in row a.

So for example the macro could say delete all columns
other than those that have "First Name", "Surname"
or "Score" in row a.

Is this possible ?

If so, can you tell me how to do it ?

Thanks in advance.
Steve



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Deleting columns based upon the value that appears in ROW A

Thanks guys.

Tom

That is exactly what I am looking for. So that i can use
it with other scenarios would you please explain which
part of the code tells me to look in row 1 only ?

One more thing...would it be possible to re-order the
columns ? i.e. "surname","first name" and "score" (in that
order) irrespective of the order they appear in the
original spreadsheet ?

Regards
Steve
-----Original Message-----
Dim rng as Range, sStr as String, i as Long
set rng = cells(1,"IV").End(xltoLeft)
for i = rng.column to 1 step -1
sStr = lcase(cells(1,i).Value)
if sStr < "first name" and _
sStr < "surname" and _
sStr < "score" then
cells(1,i).EntireColumn.Delete
end if
Next

--
Regards,
Tom Ogilvy

"Steve" wrote in

message
...
Hi

I would like to delete columns in a spreadsheet

dependant
upon the value in row a.

So for example the macro could say delete all columns
other than those that have "First Name", "Surname"
or "Score" in row a.

Is this possible ?

If so, can you tell me how to do it ?

Thanks in advance.
Steve



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting columns based upon the value that appears in ROW A

Cells(1,"IV")

cells(1,i)

the 1 means row 1.

Sub AASetColumns()
Dim rng As Range, sStr As String, i As Long
Set rng = Cells(1, "IV").End(xlToLeft)
i = rng.Column
Do
sStr = LCase(Cells(1, i).Value)
If sStr < "first name" And _
sStr < "surname" And _
sStr < "score" Then
Cells(1, i).EntireColumn.Delete

Else
Select Case sStr
Case "first name"
If i < 2 Then
Cells(1, i).EntireColumn.Cut
Columns(2).Insert
i = i + 1
End If
Case "surname"
If i < 1 Then
Cells(1, i).EntireColumn.Cut
Columns(1).Insert
i = i + 1
End If
Case "score"
If i < 3 Then
Cells(1, i).EntireColumn.Cut
Columns(3).Insert
i = i + 1
End If
End Select
End If
i = i - 1
Loop While i 0

End Sub

--
Regards,
Tom Ogilvy



"Steve" wrote in message
...
Thanks guys.

Tom

That is exactly what I am looking for. So that i can use
it with other scenarios would you please explain which
part of the code tells me to look in row 1 only ?

One more thing...would it be possible to re-order the
columns ? i.e. "surname","first name" and "score" (in that
order) irrespective of the order they appear in the
original spreadsheet ?

Regards
Steve
-----Original Message-----
Dim rng as Range, sStr as String, i as Long
set rng = cells(1,"IV").End(xltoLeft)
for i = rng.column to 1 step -1
sStr = lcase(cells(1,i).Value)
if sStr < "first name" and _
sStr < "surname" and _
sStr < "score" then
cells(1,i).EntireColumn.Delete
end if
Next

--
Regards,
Tom Ogilvy

"Steve" wrote in

message
...
Hi

I would like to delete columns in a spreadsheet

dependant
upon the value in row a.

So for example the macro could say delete all columns
other than those that have "First Name", "Surname"
or "Score" in row a.

Is this possible ?

If so, can you tell me how to do it ?

Thanks in advance.
Steve



.



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
Count rows where a specific value appears in any of 4 columns LisaM Excel Worksheet Functions 5 August 5th 09 10:46 AM
Text to columns. Only the first column appears in the wizard. Carpet Excel Discussion (Misc queries) 5 April 15th 09 07:34 AM
Count the times a value appears in a column based on another value TrainingGuru Excel Worksheet Functions 6 January 6th 09 05:43 AM
line appears when deleting chart- cannot delete it Brian Excel Worksheet Functions 2 August 20th 06 01:46 PM
Multiple columns of data saved in a CSV file appears in a single c TRR Excel Discussion (Misc queries) 2 June 8th 05 01:49 PM


All times are GMT +1. The time now is 04:06 PM.

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"