ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Edit this macro code to loop and end (https://www.excelbanter.com/excel-discussion-misc-queries/67792-edit-macro-code-loop-end.html)

GarToms

Edit this macro code to not use loops
 
The following code uses a loop to delete columns with the title 'No BU'. Given loops are slow in excel does anyone know how i can do the same function without loops.

Kevin B

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



All times are GMT +1. The time now is 06:33 PM.

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