Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Robust VBA for deletion

Posted on 2013-05-16
2
Medium Priority
?
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
gnazareth earned 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
New style of hardware planning for Microsoft Exchange server.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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