excel - If cell value is #NV get another cell -


i've got following code work with

    set sourcerange = sheets("sheet1").range("aw2:aw" & lastrow)     set resultrange = sheets("sheet2").range("a2:h" & lastrow)      = 1       each cell in sourcerange         if cell.value = 1             resultrange.rows.cells(i, 1).value = sheets("sheet1").range("o" & cell.row).value             resultrange.rows.cells(i, 2).value = sheets("sheet1").range("x" & cell.row).value             resultrange.rows.cells(i, 3).value = sheets("sheet1").range("p" & cell.row).value             resultrange.rows.cells(i, 4).value = sheets("sheet1").range("j" & cell.row).value             resultrange.rows.cells(i, 5).value = sheets("sheet1").range("k" & cell.row).value             resultrange.rows.cells(i, 6).value = sheets("sheet1").range("g" & cell.row).value             resultrange.rows.cells(i, 7).value = sheets("sheet1").range("h" & cell.row).value             resultrange.rows.cells(i, 8).value = sheets("sheet1").range("i" & cell.row).value             = + 1         end if next cell 

now problem: happens, value code:

resultrange.rows.cells(i, 2).value = sheets("sheet1").range("x" & cell.row).value 

is #nv. in case, want copy value column "aa". i've got no idea how accomplish this. there way add in code bring work? or have rewrite everything?

you may want try this:

dim cell range  set sourcerange = sheets("sheet1").range("aw2:aw" & lastrow) set resultrange = sheets("sheet2").range("a2:h" & lastrow)  = 1  strng = "o x p j k g h i" '<-- list columns index want grab data from, in order resultrange     each cell in sourcerange         if cell.value = 1             .cells(i, 1).resize(, 8).formular1c1 = split("=sheet1!" & replace(strng, " ", cell.row & " =sheet1!") & cell.row)             .cells(i, 1).resize(, 8).value = .cells(i, 1).resize(, 8).value             if .cells(i, 2) = "#nv" .cells(i, 2).value = sheets("sheet1").range("aa" & cell.row).value             = + 1         end if     next cell     .value = .value end  

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -