Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Deleting rows


I use this code to delete alle rows, that contains an "x" in the first
column:

nr = Sheets(1).Range("a65536").End(xlUp).Row


For i = nr To 2 Step -1
If UCase(Range("a" & i)) = "X" Then
Range("a" & i).EntireRow.Delete shift:=xlUp
End If
Next i

But how do I change it to delete all columns, that contains an "x" in the
first row? Thats is, what should I put in the Ucase and Range to make it
work?

nc = Sheets(1).Range("a65536").End(xlToLeft).Column

For h = nc To 2 Step -1
If UCase(???????) = "X" Then
Range(????).EntireColumn.Delete shift:=xlRight
End If
Next h

Jan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Deleting rows


Sub deletecolumnswithX()
For i = cells(1, Columns.Count) _
.End(xlToLeft).Column To 1 Step -1
If UCase(cells(1, i)) = "X" Then Columns(i).Delete
Next i
End Sub

Sub deleteRowswithX()
For i = cells(Rows.Count, 1) _
.End(xlUp).Row To 1 Step -1
If UCase(cells(i, 1)) = "X" Then Rows(i).Delete
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Jan Kronsell" wrote in message
...
I use this code to delete alle rows, that contains an "x" in the first
column:

nr = Sheets(1).Range("a65536").End(xlUp).Row


For i = nr To 2 Step -1
If UCase(Range("a" & i)) = "X" Then
Range("a" & i).EntireRow.Delete shift:=xlUp
End If
Next i

But how do I change it to delete all columns, that contains an "x" in the
first row? Thats is, what should I put in the Ucase and Range to make it
work?

nc = Sheets(1).Range("a65536").End(xlToLeft).Column

For h = nc To 2 Step -1
If UCase(???????) = "X" Then
Range(????).EntireColumn.Delete shift:=xlRight
End If
Next h

Jan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Deleting rows


I figured it out myself, finally :-)

For h = ncn To 2 Step -1
If UCase(Cells(1, h).Value) = "X" Then
Cells(1, h).EntireColumn.Delete shift:=xlRight
End If
Next h

Does the trick.

Jan


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Deleting rows


Thank you.

Jan

Don Guillett wrote:
Sub deletecolumnswithX()
For i = cells(1, Columns.Count) _
.End(xlToLeft).Column To 1 Step -1
If UCase(cells(1, i)) = "X" Then Columns(i).Delete
Next i
End Sub

Sub deleteRowswithX()
For i = cells(Rows.Count, 1) _
.End(xlUp).Row To 1 Step -1
If UCase(cells(i, 1)) = "X" Then Rows(i).Delete
Next i
End Sub

I use this code to delete alle rows, that contains an "x" in the
first column:

nr = Sheets(1).Range("a65536").End(xlUp).Row


For i = nr To 2 Step -1
If UCase(Range("a" & i)) = "X" Then
Range("a" & i).EntireRow.Delete shift:=xlUp
End If
Next i

But how do I change it to delete all columns, that contains an "x"
in the first row? Thats is, what should I put in the Ucase and Range
to make it work?

nc = Sheets(1).Range("a65536").End(xlToLeft).Column

For h = nc To 2 Step -1
If UCase(???????) = "X" Then
Range(????).EntireColumn.Delete shift:=xlRight
End If
Next h

Jan



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default Deleting rows

* * * * * * Range("a" & i).EntireRow.Delete shift:=xlUp

An very small sugestion ; if you have problems
with speed of deleting this rows , try method
ClearContents instead of Delete :
Range("a" & i).EntireRow.ClearContents shift:=xlUp

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
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Excel Programming 2 November 13th 08 01:32 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Setting up and Configuration of Excel 1 November 12th 08 06:05 PM
Help!! I have problem deleting 2500 rows of filtered rows!!!! shirley_kee Excel Discussion (Misc queries) 1 January 12th 06 03:24 AM
Help!!! I have problem deleting 2500 rows of filtered rows shirley_kee[_2_] Excel Programming 1 January 12th 06 03:15 AM
deleting hidden rows so i can print only the rows showing?????? jenn Excel Worksheet Functions 0 October 6th 05 04:05 PM


All times are GMT +1. The time now is 04:58 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"