loop command in Macro

  • Thread starter Thread starter Rasoul Khoshravan Azar
  • Start date Start date
R

Rasoul Khoshravan Azar

In Classical programming languages like Fortran and Basic we have a command
called: "Loop or Go to" which is used to run a series of commands in
recurrence until a limit or satisfying a criteria.
In Macro I want to do some commands on cells in a raw and continue same
commands for second raw until I reach to last row. I think I am looking for
some sort of equivalent of Loop in Macro.

Could you please tell what it should be? or if the philosophy of doing such
a recurring commands differ in Macro and I am thinking in a rong way in
Macro
TIA, Rasoul
 
Rasoul,

You can certainly loop in VBA. See the VBA help for Do While, Do
Until, and For Next loops.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Rasoul

This code will look through column D until it runs out of rows with data.
Uses Do/While

Sub findthings()
With ActiveSheet.Range("D:D")
Set c = .Find("xx", LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Interior.Pattern = xlPatternGray50
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub

Gord Dibben Excel MVP
 
There is also the For Each... Next loop. :)

One example would be:

For Each vnt_Variable in Range("A1:A6000")
If vnt_Variable.value = 1500 then
vnt_Variable.value = ""
End If
Next vnt_Variable

-Donna
 
Back
Top