?
Solved

Robust VBA for deletion

Posted on 2013-05-16
2
Medium Priority
?
269 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 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