i think there easy solution question, i'm having lot of trouble finding , i've been using/learning vba couple of days now.
i'm trying use vba remove space , letters usd after dollar figure. occurs in 3 specific cells in worksheet , occurs on subsequent worksheets in workbook. right i'm not worried looping through other worksheets.
below code have found works if manually select cell want code work on, tie button process happens without me having choose cell.
sub removeusd() dim cell range, str string, strlen1 integer, strlen2 integer ' each cell in current selection each cell in selection ' set strlen1 length of current cell value strlen1 = len(cell.value) ' set strlen2 original length minus 3 strlen2 = strlen1 - 3 ' set str original cell value minus last 3 characters str = left(cell.value, strlen2) ' update adjacent cell shortened value cell.value = str ' check next cell in selection next cell end sub
just input workbook name, worksheet name , range want , you. put trim
in take off leading or trailing white space. attached button, add button (developer tab > controls > insert) , select macro attach it.
sub removeusd() dim cell range, rng range dim str string dim strlen1 integer, strlen2 integer workbooks("daily msr var automation attempt") .sheets("8-30 copy") set rng = .range("e2,n2,w2") end end ' each cell in current selection each cell in rng ' set strlen1 length of current cell value strlen1 = len(cell.value) ' set strlen2 original length minus 3 strlen2 = strlen1 - 3 ' set str original cell value minus last 3 characters str = trim(left(cell.value, strlen2)) ' update adjacent cell shortened value cell.value = str ' check next cell in selection next cell end sub
Comments
Post a Comment