PC Review


Reply
Thread Tools Rate Thread

converting a simple formula into VBA code

 
 
bartman1980
Guest
Posts: n/a
 
      8th Aug 2007
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;E10;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?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      8th Aug 2007
Activecell = " =IF(A13=5;E13;IF(A12=5;E12;IF(A11=5;E11;" _
&"IF(A10=5;E10;IF(A9=5;E9;IF(A8Â*=5;E8;E7))))))

I placed a line break to conform to the line limitations of this message.
--
Best wishes,

Jim


"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;E10;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?
>
>

 
Reply With Quote
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      8th Aug 2007
I forgot to place " at the end of the formula. Hit "Post" too quickly.
--
Best wishes,

Jim


"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;E10;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?
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      8th Aug 2007
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;E10;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?
>
>

 
Reply With Quote
 
bartman1980
Guest
Posts: n/a
 
      8th Aug 2007
On 8 aug, 14:40, Jim Jackson <JimJack...@discussions.microsoft.com>
wrote:
> I forgot to place " at the end of the formula. Hit "Post" too quickly.
> --
> Best wishes,
>
> Jim
>
>
>
> "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;E10;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?- Tekst uit oorspronkelijk bericht niet weergeven -

>
> - Tekst uit oorspronkelijk bericht weergeven -


Hi Jim,
Can I fill this formula in the VBA editor as a code?

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      8th Aug 2007
Think I had the 5s and 6s reversed.

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 = 5 then
s = cells(cell.row,"E").Value
elseif cell.Value = 6 then
cells(cell.row,"D").value = s
end if
Next
End Sub

This assumes that the description on a 5 row is in a lower number row than
the type 6 row where it needs to be copied.

row 2 5
row 3 6
row 4 6
row 5 6
row 6 5
row 7 6

so the description in E2 would be copied to D35, E6 to D7.

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote:

> 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;E10;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?
> >
> >

 
Reply With Quote
 
bartman1980
Guest
Posts: n/a
 
      8th Aug 2007
On 8 aug, 14:50, Tom Ogilvy <TomOgi...@discussions.microsoft.com>
wrote:
> Think I had the 5s and 6s reversed.
>
> 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 = 5 then
> s = cells(cell.row,"E").Value
> elseif cell.Value = 6 then
> cells(cell.row,"D").value = s
> end if
> Next
> End Sub
>
> This assumes that the description on a 5 row is in a lower number row than
> the type 6 row where it needs to be copied.
>
> row 2 5
> row 3 6
> row 4 6
> row 5 6
> row 6 5
> row 7 6
>
> so the description in E2 would be copied to D35, E6 to D7.
>
> --
> Regards,
> Tom Ogilvy
>
>
>
> "Tom Ogilvy" wrote:
> > 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;E10;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?- Tekst uit oorspronkelijk bericht niet weergeven -

>
> - Tekst uit oorspronkelijk bericht weergeven -


Hi Tim,
This works perfect, thank you very much!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a simple formula that will remove all duplicates in a simple list john Microsoft Excel Misc 1 19th Nov 2010 09:32 AM
IF formula-simple question; simple operator Rich D Microsoft Excel Misc 4 6th Dec 2007 03:36 PM
Simple problem, simple formula, no FUNCTION ! =?Utf-8?B?Um9uQEJ1eQ==?= Microsoft Excel Worksheet Functions 6 28th Sep 2007 04:51 PM
Help Converting Cell Formula To VBA Code Minitman Microsoft Excel Programming 5 4th Nov 2004 08:03 PM
simple? pasting simple formula, error on copy sns Microsoft Excel Discussion 4 11th Jan 2004 12:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:40 AM.