Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

deleting columns with criteria

  Asked By: Adella    Date: Feb 22    Category: MS Office    Views: 822
  

Need a little help in making some code more effecient.

I am importing some data that onto a new sheet that need to be very specific as
it is linked to a number of pivot tables.

I wish to import the raw data and delete a number of rows so that the new column
headings match the old ones. I thought of simply searching and deleting rows
(see code below) but does anyone know if there is a more effecient way, so that
for example, if A1 heading <> A2 heading then delete new data?

Also does anyone know how to repeat this macro until no more results are found?
i.e. until all the unwanted headings have been deleted without continually
repeating the code.

Many thanks ijn advance.



Sub delete()
' Go to the "Heading1" Column.
Rows("2:2").Select
Selection.Find(What:="Heading1", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Select
Range(ActiveCell, ActiveCell.Offset(6536, 0)).Select
Selection.delete Shift:=xlToLeft
Rows("2:2").Select
Selection.delete Shift:=xlUp
Range("A1").Select

End Sub

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on deleting columns with criteria Or get search suggestion and latest updates.




Tagged: