ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete Columns with duplicate headers (https://www.excelbanter.com/excel-programming/363155-re-delete-columns-duplicate-headers.html)

Tom Ogilvy

Delete Columns with duplicate headers
 
For lCol = Columns("P").Column To Columns("L").Column Step -1

is the same as

for lCol = 16 to 12 step -1

confirming from the immediate window:

? columns("P").column
16
? columns("L").column
12



--
Regards,
Tom Ogilvy


"Ardus Petus" wrote:

Hi Casey

Sub DelDupeCols()
Dim lCol As Long
Dim rFound As Range
For lCol = Columns("P").Column To Columns("L").Column Step -1
Set rFound = Range(Range("K1"), Cells(1, lCol - 1)).Find( _
what:=Cells(1, lCol).Value, _
LookIn:=xlValues, _
lookat:=xlWhole)
If Not rFound Is Nothing Then
Columns(lCol).Delete
End If
Next lCol
End Sub

HTH
--
AP

"Casey" a écrit dans le
message de news: ...

Hi,
I have a range of column headers ("K1:IP1") that I would like to loop
through and find all duplicates. Then delete the entire column with the
duplicate header. I would like to keep the original header and column.
Example:
K L M N O
P..........................
Stone CMU Brick Grout Stone Stone

Columns O & P would be deleted but column K would remain.


--
Casey


------------------------------------------------------------------------
Casey's Profile:
http://www.excelforum.com/member.php...fo&userid=4545
View this thread: http://www.excelforum.com/showthread...hreadid=547921






All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com