Solved

Robust VBA for deletion

Posted on 2013-05-16
2
263 Views
Last Modified: 2013-05-16
Hello All,

I need a robust vba ode that does this.
This robust function takes in a string and worksheet as parameters.

For example
myFunc (“Aron”,sheet1)
will delete  all the columns that has  occurrences of Aaron within sheet1 at row 2
 Also criteria for clearing will be that the target string should be part of the entire cell value,
For example -  if a cell has Aaron 3455  then then cell will not be cleared. So xlWhole, not xlPart
0
Comment
Question by:Rayne
2 Comments
 
LVL 3

Accepted Solution

by:
gnazareth earned 500 total points
ID: 39172084
Try this...

Function DeleteColumns(val, sheetName)
    With Sheets(sheetName)
        finalColumn = .Cells(2, .Columns.Count).End(xlToLeft).Column
        currColumn = 1
        While currColumn <= finalColumn
            If .Cells(2, currColumn).Value = val Then
                .Cells(2, currColumn).EntireColumn.Delete
                finalColumn = finalColumn - 1
            Else
                currColumn = currColumn + 1
            End If
        Wend
    End With
End Function

Open in new window

0
 

Author Comment

by:Rayne
ID: 39172119
works like a charm
thank you :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Outlook Free & Paid Tools
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now