excel - Create a Macro to convert UPC E Barcode to UPC A -
my problem after first loop oldupc still referenced a1 not off setting a2, created msgboxes track progress in loop. need offset every cell?
sub convertupce()
dim oldupc string dim newupc string dim k double, double dim l integer oldupc = activecell.offset(0, -2).value newupc = activecell.offset(0, 1).value k = cells(rows.count, "a").end(xlup).row l = activecell.value msgbox (k) 'msgbox oldupc 'msgbox newupc 'msgbox l range("c1").select = 1 11 if (l >= 0 , l <= 3) activecell.value2 = "'" & mid(oldupc, 1, 1) & mid(oldupc, 2, 2) & mid(oldupc, 7, 1) & "0000" & mid(oldupc, 4, 3) activecell.offset(1, 0).select elseif (l = 4) activecell.value2 = "'" & mid(oldupc, 1, 1) & mid(oldupc, 2, 3) & "00000" & mid(oldupc, 5, 2) elseif (l = 5) activecell.value2 = "'" & mid(oldupc, 1, 1) & mid(oldupc, 2, 4) & "00000" & mid(oldupc, 6, 1) activecell.offset(1, 0).select elseif (l >= 6 , l <= 9) activecell.value2 = "'" & mid(oldupc, 1, 1) & mid(oldupc, 2, 5) & "0000" & mid(oldupc, 7, 1) activecell.offset(1, 0).select else: activecell.value = "not vailid check digit" end if 'msgbox oldupc msgbox oldupc next
i recommend against using activecell , instead use iteration integer cell row.
like so: cells(i, 3).value2 = ..., row number , 3 column number (since in column c).
then can offset cells(i,3).offset(1,0).select.
this make code run faster since not selecting each cell before manipulate data.
tip: if want iterate through rows , columns, can following , not worry selected , next:
for rownum = 1 11 colnum = 1 11 cells(rownum, colnum).value = "" next colnum next rownum -so run through 11 columns each row 11 rows!
Comments
Post a Comment