Looped If/Then Functions in Excel VBA -


i'm starting learn excel vba , i'm running problems particular exercise. given column of 20 randomly generated integers between 0 , 100 in column, want write vba program writes in column next "pass" if number greater or equal 50 , "fail" if number less 50.

my approach involved using looping function = 1 20 if statement each cell (i,1) write pass or fail in (i,2).

sub commandbutton1_click() 'declare variables dim score integer, result string, integer  'setup loop function, if/then function = 1 20     score = sheet1.cells(i, 1).value     if score >= 60 result = "pass"     sheet1.cells(i, 2).value = result next  end if end sub 

could insight i'm doing wrong?

thanks in advance!

try this...

sub commandbutton1_click() 'declare variables dim score integer, result string, integer  'setup loop function, if/then function = 1 20     score = sheets("sheet1").cells(i, 1).value     if score >= 60         result = "pass"     else         result = "fail"    end if     sheets("sheet1").cells(i, 2).value = result  next  end sub 
  1. you need specify worksheet working sheets("sheet1").cells(...

  2. add else clause set result fail when value less 60. otherwise never changes after first 'pass'

  3. move end if inside loop, after score check...


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -