Macros

U

Unday

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
 
R

Rick

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
 
D

Don Guillett

for each c in selection
if c>0 then c.cut c.offset(0,5)
next c


--
Don Guillett
SalesAid Software
[email protected]
Unday said:
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
 
U

unday

Rick
If you're out there, thanks. Your solution works like a charm

Regards

Unda

----- Rick wrote: ----

Hi

There's at least two different ways to write this

Sub SimpleMacro1(

Dim Cel As Varian

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

End Su

Sub SimpleMacro2(

Dim i As Intege

For i = 1 To 2
If Cells(i, 4).Value > 0 The
Cells(i, 7).Value = Cells(i, 5).Valu
ElseIf Cells(i, 4).Value = 0 The
Cells(i, 7).Value = Cells(i, 6).Valu
End I
Next

End Su

HTH - Ric
-----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 rang
 
Top