Excel VBA Find data that is not equal to 0 and copy Row header -


i have spreadsheet need create macro , need guys help.

the big picture, want find cell in range not equal 0 (its either 0 or 1 in cell range) , copy title of column , paste in l cell of same row found 1.

so goes this:

row n2 wi2 has titles of columns, range n3 wi9000 location of cells either 1 or 0 --- 1 if value exist , 0 if not found

ex:

3   apples bananas tomatoes 4        1       1        0 5        0       0        1 6        1       0        0 

and when sees 1's or not equal 0:

  • number 4 in cell l4 output (apples, bananas)
  • number 5 in cell l5 output (tomatoes)
  • number 6 in cell l6 output (apples)

thanks help

do old school ↓↓↓ or use range.findnext(previousfind)

sub fruitsorter()         dim xrow long         dim xcolumn long         dim lastcolumn long         'dont forget use cleaner - (desired)range.clearcontents before running         xrow = 4 'seen in example edit         xcolumn = 1 'seen in example edit         lastcolumn = 4 'your last column want fruit written          'loop rows             'loop columns                 select case cells(xrow, xcolumn).value 'checks if cell contains 1                     case 1 'if 1 below                         if cells(xrow, lastcolumn) = "" 'if first time cell modified                             cells(xrow, lastcolumn) = cells(3, xcolumn).value 'write data                         else 'if cell contains fruit                             cells(xrow, lastcolumn) = cells(xrow, lastcolumn) & ", " & cells(3, xcolumn).value 'insert value thet in cell plus new 1                         end if                     case 0 'nothing happens                 end select                 xrow = xrow + 1 'move 1 row forward             loop until cells(xrow, xcolumn) = "" 'will loop until cell under table empty can set other specified condition row number(until xrow=200)             xcolumn = xcolumn + 1  'move 1 column forward             xrow = 4 'move beginning         loop until xcolumn = lastcolumn 'will loop until xcolumn reaches last column fruit being written     end sub 

hope helps


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -