excel vba - VBA Loop and copy regions from sheet to sheet -


i trying loop down column "q" on active sheet, find values in between 27 , 40 , copy cell along region around cell noted (-1, -16) new sheet.

right making region bold make sure loop catching right values , regions.

i"m new vba if can give me pointers or advise on how solve problem i'd appreciative.

sub test2() application.screenupdating = false activesheet.range("q13").select let x = 0 while x < 500     if activecell.value >= 27 , activecell.value <= 40         range(activecell, activecell.offset(-1, -16)).select         selection.font.bold = true         activecell.offset(2, 16).activate     else         activecell.offset(1, 0).select     end if     x = x + 1 loop end sub 

try below code :

  • always set screenupdating property true when macro ends.check link
  • avoid using select/activate in code. check link
  • always explicitly specify sheet when working more 1 sheet.
  • avoid using activecell,activesheet , refer them explicitly.
sub test2()      application.screenupdating = false       dim lastrow long     lastrow = sheets("sheet1").range("q" & rows.count).end(xlup).row      dim rng range, cell range     set rng = sheets("sheet1").range("q1:q" & lastrow)      each cell in rng          if cell.value >= 27 , cell.value <= 40             sheets("sheet1").range(cell, cell.offset(0, -16)).copy sheets("sheet2").cells(sheets("sheet2").range("q" & rows.count).end(xlup).row + 1, 1)         end if     next      application.screenupdating = true end sub 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -