excel - Add 1 to a value if name is equal to a string on a different sheet -
i trying make kind of inventory. when on second sheet add name of product, adds 1 inventory had in first sheet in row e product. list of names put in 2nd sheet instead of 1 name tried out in vba code here.
after done list should able clear sheet 2 , values stay saved. when try gives error , don't know how make work letting go on entire list.
private sub commandbutton1_click() dim x integer x = sheets("sheet1").cells(1, "e").value each cell in sheets(sheet1).range("a:a") if cell.value = sheets("sheets2").cells(1, "a").value x = x + 1 end if next cell end sub
you thinking x
represents cell, memory variable starts value in e1 on sheet1.
if want range increase make variable range , set range desired, or skip together:
private sub commandbutton1_click() dim cell range worksheets("sheet1") each cell in intersect(.range("a:a"),.usedrange) .range("e1").value = .range("e1").value + application.worksheetfunction.countif(worksheets("sheet2").range("a:a"),cell.value) next cell end end sub
Comments
Post a Comment