excel - Selecting range based on cells and return the adjacent cell -
greeting, trying find function formula or vba macro solve problem. appreciate support , in matter. have list in column c can see , specific cell between range of data based on range selecting in case numbers in column f. example: select cells between 1000 , 2000 specific cell called “ apple” in g2 return adjacent cell using offsets formula d4 “ red” solution right table data filled based on range specified. thank in advance support.
d
the code isn't dynamic works if columns table static.
dim row byte, lastrow byte dim currentnumber long dim currenttext string activeworkbook.sheets(1) lastrow = .cells(.rows.count, "b").end(xlup).row row = 2 lastrow if not (isempty(.cells(row, 2))) if (isnumeric(.cells(row, 2))) currentnumber = .cells(row, 2) elseif (len(.cells(row, 2) > 0)) currenttext = .cells(row, 2) select case currentnumber case 1000 if strcomp(currenttext, "apple", vbtextcompare) = 0 .cells(3, 6) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "banana", vbtextcompare) = 0 .cells(3, 7) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "orange", vbtextcompare) = 0 .cells(3, 8) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "mobile", vbtextcompare) = 0 .cells(3, 9) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "car", vbtextcompare) = 0 .cells(3, 10) = .cells(row, 2).offset(0, 1) end if case 2000 if strcomp(currenttext, "apple", vbtextcompare) = 0 .cells(4, 6) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "banana", vbtextcompare) = 0 .cells(4, 7) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "orange", vbtextcompare) = 0 .cells(4, 8) = .cells(row, 2).offset elseif strcomp(currenttext, "mobile", vbtextcompare) = 0 .cells(4, 9) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "car", vbtextcompare) = 0 .cells(4, 10) = .cells(row, 2).offset(0, 1) end if case 5000 if strcomp(currenttext, "apple", vbtextcompare) = 0 .cells(5, 6) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "banana", vbtextcompare) = 0 .cells(5, 7) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "orange", vbtextcompare) = 0 .cells(5, 8) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "mobile", vbtextcompare) = 0 .cells(5, 9) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "car", vbtextcompare) = 0 .cells(5, 10) = .cells(row, 2).offset(0, 1) end if case 7000 if strcomp(currenttext, "apple", vbtextcompare) = 0 .cells(6, 6) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "banana", vbtextcompare) = 0 .cells(6, 7) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "orange", vbtextcompare) = 0 .cells(6, 8) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "mobile", vbtextcompare) = 0 .cells(6, 9) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "car", vbtextcompare) = 0 .cells(6, 10) = .cells(row, 2).offset(0, 1) end if case 10000 if strcomp(currenttext, "apple", vbtextcompare) = 0 .cells(7, 6) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "banana", vbtextcompare) = 0 .cells(7, 7) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "orange", vbtextcompare) = 0 .cells(7, 8) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "mobile", vbtextcompare) = 0 .cells(7, 9) = .cells(row, 2).offset(0, 1) elseif strcomp(currenttext, "car", vbtextcompare) = 0 .cells(7, 10) = .cells(row, 2).offset(0, 1) end if end select end if end if next row end
Comments
Post a Comment