Solved

Robust VBA for deletion

Posted on 2013-05-16
2
264 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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 will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

776 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