converting a simple formula into VBA code
Try this on a copy of your spreadsheet.
Change the 2 to row of the first cell that you want to process
Sub CopyDescriptions
Dim rng1 as Range, cell as Range
set rng1 = Range(cells(2,"A"),cells(rows.count,"A").End(xlup) )
for each cell in rng1
if cell.Value = 6 then
s = cells(cell.row,"E").Value
elseif cell.Value = 5 then
cells(cell.row,"D").value = s
end if
Next
End Sub
--
Regards,
Tom Ogilvy
"bartman1980" wrote:
I want to convert the formula into a VBA code, only I don;t know
excatly how to do this.
This is my formula:
=IF(A13=5;E13;IF(A12=5;E12;IF(A11=5;E11;IF(A10=5;E 10;IF(A9=5;E9;IF(A8Â*
=5;E8;E7))))))
This is what he supposed to do:
On each row in column E is an articlegroup or articlenumber.
Next to the articlegroup is a description.
Example:
There are 3 different partnumbers with their own description, BUT they
all have a common desciption.
So basically I have to copy the description of the articlegroup next
to the desription of the articlenumber.
In column A are cells with a 5 or 6.
If there is a 5, than there is an articlegroup description which
should be copied next to the articlenumber.
If there is a 6, than he should look one cell above to look if there
is a five. And he has to repeat this when he finds the 5.
I was thinking about this one:
On Error GoTo End
For i = Sheets(1).Range("a65000").End(xlUp).Row To 1 Step -1
If Cells("A" & i - 2) = 5 Then
Cells("E" & i).Select
Selection.Copy
Cells("D" & i - 1).Select
Selection.Paste
Else
End If
Next
End:
But this doesn't work prettig much.
Can somebody help me how to handle this?
|