Solved

Robust VBA for deletion

Posted on 2013-05-16
2
261 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
Comment Utility
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
Comment Utility
works like a charm
thank you :)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

763 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

11 Experts available now in Live!

Get 1:1 Help Now