Thread: Macros
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
rick rick is offline
external usenet poster
 
Posts: 25
Default Macros

Hi,

There's at least two different ways to write this:

Sub SimpleMacro1()

Dim Cel As Variant

For Each Cel In Range("D1:D21")
If Cel 0 Then
Cel.Offset(0, 3).Value = Cel.Offset(0, 1).Value
ElseIf Cel = 0 Then
Cel.Offset(0, 3).Value = Cel.Offset(0, 2).Value
End If
Next Cel

End Sub

Sub SimpleMacro2()

Dim i As Integer

For i = 1 To 21
If Cells(i, 4).Value 0 Then
Cells(i, 7).Value = Cells(i, 5).Value
ElseIf Cells(i, 4).Value = 0 Then
Cells(i, 7).Value = Cells(i, 6).Value
End If
Next i

End Sub

HTH - Rick

-----Original Message-----
I'm trying to write a macro that will cut and paste cells

in the same row to different columns in the same row
based on the cell value in the test cell in a range of
cells. If the value of the test cell is 0 the macro
will perform the functions programmed. If the value in
the test cell = 0 the macro will go to the next cell and
continue through the entire range
.