ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   prob with deleting columns (https://www.excelbanter.com/excel-programming/368175-prob-deleting-columns.html)

ruchie

prob with deleting columns
 
i need to create a macro to delete columns from my worksheet, which are
non-blank, and dont occur at an interval. what can be the way out for
that?


[email protected][_2_]

prob with deleting columns
 
Can you read column titles into an array and apply your
delete/no-delete criteria based on their contents ?


ruchie wrote:
i need to create a macro to delete columns from my worksheet, which are
non-blank, and dont occur at an interval. what can be the way out for
that?



ruchie

prob with deleting columns
 
since im sooo new to this, i dont know if i can do that or not. is it
possible that way?


[email protected][_2_]

prob with deleting columns
 
Absolutely possible.. I use this type of subroutine to parse large
reports of columns that are not useful to me..

Start by creating a Title Row array of Column titles that you know are
trash..
strTitles(1) = "Garbage"
strTitles(2) = "more Garbage"
strTitles(3) = "You get the idea"

Next use a find subroutine to locate the Column and Row position of the
expected Title.
Sub FindMe(SearchWord)
SearchRow = ActiveSheet.Cells.Find(SearchWord, LookIn:=xlValues,
LookAt:= _
xlWhole).Row
SearchCol = ActiveSheet.Cells.Find(SearchWord, LookIn:=xlValues,
LookAt:= _
xlWhole).Column
End Sub

Then delete the column and advance to the next title to look for......
For z = 1 To IntLastCol
Cells(TitlesRow(1), z).Select
If IsError(Application.Match(ActiveCell.Value, strTitles, 0)) Then
Range(Cells(TitlesRow(1), z), Cells(LastRow, z)).Select
Selection.Delete Shift:=xlUp
End If
Next

Note.. you don't want to assign all of the positions at the start since
on delete your report will shift unless you use the [Selection.Delete
Shift:=xlUp] function, thereby changing the location of the columns..

Test your code first by looking for the title you expect to remove then
changing the Interior color.. you'll quickly know if your code is
working as expected.


HTH,
Will

ruchie wrote:
since im sooo new to this, i dont know if i can do that or not. is it
possible that way?



ruchie

prob with deleting columns
 
thanks a ton!



All times are GMT +1. The time now is 01:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com