'A' + 1 != 'B' --------------------------------- 'A' + 1 does not equal 'B'.
'A' + 1 = Error Type Mismatch ------------ 'A' + 1 will just give you an error.
'A'&1 = A1 ----------------------------------- This would simply be combining them.
This gets the corresponding Letter for a Number (number for a column. Like the 4th column = D etc.)
X = 1
LEFT(ADDRESS(1, x), 1) = A
X = 2
LEFT(ADDRESS(1, x), 1) = B
Etc.
And this was typed up in a sleep deprived state at home where I don't have Excel in order to test the code. If there are problems, which I'm expecting considering my need of sleep and the fact I can't find my glasses... Let me know. I'll fix it when I'm at work tomorrow where I have all of my resources.
Code
Sub DeleteDups()
Set lastcell = Cells.SpecialCells(xlLastCell)
lCols = lastcell.Column
letLCols = ADDRESS(1,lCols)
Dim x As Long
Dim y As Long
Dim LastRow As Long
LastRow = Range("A65536").End(xlUp).Row
For x = 1 To LastRow
For y = 1 To lCols
If Application.WorksheetFunction.CountIf(LEFT(ADDRESS(1,y), 1)& x & ":" LEFT(ADDRESS(1,y), 1), Range(LEFT(ADDRESS(1,y), 1) & X).Text) > 1 Then
Range("A" & x).EntireColumn.Delete
End If
Next
Next x
End Sub
Logic = For each row, please check each columns corresponding cell for that row 1 by 1 to see if that cells contents exist anywhere else in the row and if they do we need to get rid of that column. Repeat as necessary, and then nothing further.
I was taught if you can't make a english statement with your code your doing it wrong :/.... old habits dying hard.
A good question would be... do you want the script to automatically scoot everything to the left to fill the empty space deleting the column is going to create? If do do the following:
Replace: Range("A" & x).EntireColumn.Delete
With this: Range("A" & x).EntireColumn.Delete Shift:=xlToLeft
Easy peasy if my memory serves me correct.
This post was edited by dreu21952006 on Jul 25 2012 11:58pm