excel - VBA Macro to assess cells in a variable range of columns and rows and output a binary number in a new worksheet -
i have following code:
dim trimthreshold integer dim counter integer dim currentcolumn string set ws1 = activeworkbook.sheets("data hub") set ws2 = activeworkbook.sheets("sheet2") trimthreshold = sheets("sheet2").range("b3").value counter = 0 currentcolumn = "b2" sheets("data hub").activate each cell in range(currentcolumn, range(currentcolumn).end(xldown)) if cell.value >= trimthreshold sheets("sheet2").range("c3").offset(counter, 0).value = 1 counter = counter + 1 else sheets("sheet2").range("c3").offset(counter, 0).value = 0 counter = counter + 1 end if next cell this code works 1 column there anyway assess variable range of both columns , rows? instance, data may attached picture:
but columns , rows may variable between data worksheets (the columns , rows equal within single worksheet though!)
the final output binary number (either 1 or 0) in next tab of worksheet determined if value of cell greather threshold value entered in cell (sheet2.cell"b3" in case).
thank you!
should self-explaining:
option explicit sub macro1() sheets("data hub") dim inrange range set inrange = .range("b2") set inrange = .range(inrange.end(xltoright), inrange.end(xldown)) dim wsout worksheet set wsout = activeworkbook.sheets("sheet2") dim trimthreshold long trimthreshold = wsout.range("b3").value dim outrange range set outrange = wsout.range("c3").resize(inrange.rows.count, inrange.columns.count) outrange.value = .evaluate("(" & inrange.address & ">=" & trimthreshold & ")*1") end end sub if still have questions, ask :)

Comments
Post a Comment