ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop Formula (https://www.excelbanter.com/excel-programming/389768-loop-formula.html)

Shawn

Loop Formula
 

I have a range of cells lets say A1:B10. In Column B, there is an "x" every
so often. I need a macro that will look down Column B1:B10 and for every
time there is an "x" copy what is in the adjacent cell in Column A to Sheet1
cell A1 then A2 then A3 etc.

Please helpt.


--
Thanks
Shawn

Tom Ogilvy

Loop Formula
 
Sub CopyData()
Dim rng as Range, cell as Range
dim rw as Long
set rng = Worksheets("Sheet2").Range("B1:B10")
rw = 1
for each cell in rng
if lcase(cell.value) = "x" then
worksheets("Sheet1").Cells(rw,"A") = cell.offset(0,-1)
rw = rw + 1
end if
Next
End sub

--
Regards,
Tom Ogilvy



"Shawn" wrote:


I have a range of cells lets say A1:B10. In Column B, there is an "x" every
so often. I need a macro that will look down Column B1:B10 and for every
time there is an "x" copy what is in the adjacent cell in Column A to Sheet1
cell A1 then A2 then A3 etc.

Please helpt.


--
Thanks
Shawn



All times are GMT +1. The time now is 05:14 AM.

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