LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Loop Until Desired Columns left

Dave,

Your explanation makes perfect sense and solution works great.

thanks !



"Dave Peterson" wrote:

When you delete rows, it's easier to start at the bottom and work your way to
the top.

When you delete columns, it's easier to start at the far right and work your way
to the left.

Dim iCol As long
dim LastCol as long

with worksheets("Sheetnamehere")
lastcol = .cells(1,.columns.count).end(xltoleft).column
for icol = lastcol to 1 step -1
select case lcase(.cells(1,icol).value)
case is = "doc. date", "type", "reference", "lc amnt"
'skip it
case else
.columns(icol).delete
end select
next icol
end with

Sometimes "select case" makes it a bit easier to see what's going on.

SteveT wrote:

Hello,

I'm using JLGWhiz's solution in posting "Deleting Column Based On Header"
to delete columns other than those correctly titled. - Below -

It works Fine but only when run several times or repeated.

Can someone help me enhance to automatically loop until either desired # of
columns with data or until Column Headers indicated below all that left ?

Dim C As Range
lc = Cells(1, Columns.Count).End(xlToLeft).Column
Set myRng = Range("A1", Cells(1, lc))
For Each C In myRng
If C < "Doc. Date" And C < "DocumentN" And C < "Type" And C <
"Reference" And C < "LC amnt" Then
C.EntireColumn.Delete
End If
Next

Many Thanks / Happy Holidays
Steven
all left


--

Dave Peterson

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
In Excel My Columns are going from right to left, how can I fix i. N 1000 Excel Discussion (Misc queries) 1 November 9th 07 12:34 AM
If < equal to named list require user to fill out desired columns? Matt Pierringer Excel Programming 2 March 7th 07 10:04 PM
Count number of times two columns have desired values Gavin Deveau Excel Discussion (Misc queries) 2 June 16th 06 06:29 PM
My columns run from right to left instead of left to right. Help? Marleneburton Setting up and Configuration of Excel 1 March 21st 06 08:31 AM
filtering columns-left nav agrillo Charts and Charting in Excel 0 December 1st 05 08:40 PM


All times are GMT +1. The time now is 10:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"