Trying to change text in cells in Excel -
i haven't used vba in excel in decade wanted find coding solution changing bunch of text in on 20k cells. job has me doing manually, know there has comp sci solution.
i've sorted column need change. , there thousands of duplicates need changed such below example shows
example: 1001.tif changed 1001_1.tif if first duplicate or leave if it's first text of value.
my code below doesn't work @ should framework it.
sub button1_click() dim n integer n = 1 dim test string test = cells(1, d).text dim active string active = cells(2, d).text = 2 12 active = cells(i, d) if active = test cells(i, d).text = microsoft.visualbasic.strings.left(test, 4) + "_" + n + ".tif" n = n + 1 else test = active end if next cells(1, a).text = "done" end sub
any tips?
in case have aversion vba, here implementation in-cell formula of same approach current vba answer. assuming d column of filenames:
=if(countif($d$2:d2,d2) > 1, mid(d2, 1, find(".", d2) - 1) & "_" & countif($d$2:d2, d2) & ".tif", d2) same.
some explanation: countif() formula counts number of occurrences of string top of column ($d$2) current row. mid/find formula puts number of occurrences , underscore in place before . in filename. find gets place of ., mid cuts string off right before dot, rest of formula appends number , file extension. work numbers longer 4 characters.
Comments
Post a Comment