LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.misc
Kevin B
 
Posts: n/a
Default Edit this macro code to loop and end

You can try this:

Sub DelCol()

Dim iColCount As Integer
Dim varVal As Variant

Range("A1").Select
varVal = ActiveCell.Value

Do Until iColCount = 256
varVal = ActiveCell.Value
If varVal = "No BU" Then Selection.EntireColumn.Delete
If ActiveCell.Column < 256 Then ActiveCell.Offset(0, 1).Select
iColCount = iColCount + 1
Loop

--
Kevin Backmann


"GarToms" wrote:


I use this macro code to delete columns in a table that are headed 'No
BU'. Currently I press it until all the 'No BU' columns are deleted.
Once all the columns have been deleted it displays a 91 error.

Does anyone know how to edit this macro code to loop it (so i dont have
to repress the button), and finish the macro when there are no more 'No
BU' columns to delete (without the error).

Sub DeleteColumns()
'
' DeleteColumns Macro
' Macro recorded 27/01/2006 by Corus
'

'
Cells.Find(What:="No BU", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.LargeScroll ToRight:=-5
Range("B10").Select
End Sub


--
GarToms

 
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



All times are GMT +1. The time now is 01:19 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"