vba - Excel countIf + concatenate function -


i have excel formula simple count if. however, want add condition that, if met change fill colour of cell. example: in sheet 1 cell a1 have "xxx". in sheet 1 cell a2 have boolean of "true". in sheet 2 cell b1, have

    =countif(a1,"*xxx*") 

what want if in sheet 1 cell a1 have xxx , sheet 1 cell a2 "true" in sheet 2 cell b1 should have "1" displayed within red cell

an alternate color coding if sheet 1 cell a2 has boolean of "true" , sheet 1 cell a1 has xxx on sheet 2 cell b1, should have "1r" displayed.

any appreciated

if want vba, code want:

option explicit sub test()  dim wb workbook dim ws1 worksheet, ws2 worksheet dim lastrow long dim long  set wb = thisworkbook set ws1 = wb.sheets("sheet1") 'change name of sheet set ws2 = wb.sheets("sheet2") 'change name of sheet  lastrow = ws1.cells(rows.count, 1).end(xlup).row  = 1 lastrow step 2      if ws1.cells(i, "a") = "sec" , ws1.cells(i + 1, "a") = true         ws2.cells(i, "b") = 1         ws2.cells(i, "b").interior.color = rgb(255, 0, 0) '       ws2.cells(i, "b") = "1r" ' alternate color coding     end if  next  end sub 

edit:

code based on commnents below

option explicit sub test()  dim wb workbook dim ws1 worksheet, ws2 worksheet dim lastrow long dim long, c long  set wb = thisworkbook set ws1 = wb.sheets("sheet1") 'change name of sheet set ws2 = wb.sheets("sheet2") 'change name of sheet  = 3     c = 7 25           if ws2.cells(i, "k") > 0 , ws2.cells(i, "l") = false             ws1.cells(3, c).interior.color = rgb(255, 0, 0)          elseif ws2.cells(i, "k") > 0 , ws2.cells(i, "l") = true             ws1.cells(3, c).interior.color = rgb(0, 255, 0)         end if = + 2  next c   end sub 

Comments