ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba conditional loops (https://www.excelbanter.com/excel-programming/356323-vba-conditional-loops.html)

Benoit

vba conditional loops
 
This one should be easy for someone used to vba.
I've got three named ranges on the same sheet called "DataDownload"
(LSRatio, LongPrice, ShortPrice).
LSRatio is the range I want to populate
LongPrice and ShortPrice are price series going down different columns.
I want to do a loop in the LSRatio range that first checks that LongPrice
and ShortPrice are not empty, and if this is the case, calculate LSRatio as
LongPrice/ShortPrice until I reach the point where LongPrice and ShortPrice
end (ie cells become empty) at which point the procedure ends.
Any help would be greatly appricated

Tom Ogilvy

vba conditional loops
 
Assume Longprice and Shortprice will be the same size and populated to the
same extent

i = 0
for each cell in Rane("shortprice")
i = i + 1
if not isempty(cell) then
range("lsratio")(i).Value = Range("Longprice")(i).Value/cell.Value
else
exit for
end if
Next

--
Regards,
Tom Ogilvy


"Benoit" wrote:

This one should be easy for someone used to vba.
I've got three named ranges on the same sheet called "DataDownload"
(LSRatio, LongPrice, ShortPrice).
LSRatio is the range I want to populate
LongPrice and ShortPrice are price series going down different columns.
I want to do a loop in the LSRatio range that first checks that LongPrice
and ShortPrice are not empty, and if this is the case, calculate LSRatio as
LongPrice/ShortPrice until I reach the point where LongPrice and ShortPrice
end (ie cells become empty) at which point the procedure ends.
Any help would be greatly appricated



All times are GMT +1. The time now is 07:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com