Hello duugg,
You're full of questions today. Are these column names in row 1?
Hello duugg,
You're full of questions today. Are these column names in row 1?
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
LOL,
Yes
Thanks
Hello Duugg,
This macro finds the columns, and makes the "Purple" column the same size as "Customer Number" column. The "Purple" column is then checked for any blanks. If any blanks are found then the entire column is deleted.
![]()
Sub Macro1() Dim Col As Long Dim LastCol As Long Dim Rng As Range Dim Rng1 As Range Dim Rng2 As Range LastCol = Cells(1, Columns.Count).End(xlToLeft).Column Set Rng = Range("A1", Cells(1, LastCol)) For Each Cell In Rng Col = Col + 1 Select Case Rng.Value Case Is = "Customer Number" Set Rng1 = Cells(Rows.Count, Col).End(xlUp) Case Is = "Purple" Set Rng2 = Cells(Rows.Count, Col).End(xlUp) Set Rng2 = Resize(Rng1.Rows.Count, 1) End Select Next Cell If Rng1 Is Nothing Then MsgBox "Customer Number column not found." Exit Sub End If If Rng2 Is Nothing Then MsgBox "Purple column not found." Exit Sub End If On Error Resume Next Col = Rng2.SpecialCells(xlCellTypeBlanks).Count If Err = 0 Then Rng2.EntireColumn.Delete End Sub
Leith,
I got this error
Compile error:
Sub or Function not defined
Hello Duugg,
It appears I left off a qualifier on the Resize method.
![]()
Sub Macro1() Dim Col As Long Dim LastCol As Long Dim Rng As Range Dim Rng1 As Range Dim Rng2 As Range LastCol = Cells(1, Columns.Count).End(xlToLeft).Column Set Rng = Range("A1", Cells(1, LastCol)) For Each Cell In Rng Col = Col + 1 Select Case Rng.Value Case Is = "Customer Number" Set Rng1 = Cells(Rows.Count, Col).End(xlUp) Case Is = "Purple" Set Rng2 = Cells(Rows.Count, Col).End(xlUp) Set Rng2 = Rng2.Resize(Rng1.Rows.Count, 1) End Select Next Cell If Rng1 Is Nothing Then MsgBox "Customer Number column not found." Exit Sub End If If Rng2 Is Nothing Then MsgBox "Purple column not found." Exit Sub End If On Error Resume Next Col = Rng2.SpecialCells(xlCellTypeBlanks).Count If Err = 0 Then Rng2.EntireColumn.Delete End Sub
Sorry Leith,
I got Runtime error 13 Type mismatch
Hello Duugg,
I have had such bad luck answering your posts. Which line has the error?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks