Excel VBA that loops through the folder and move data to the next column -
i trying write macro loop through files in folder m opens , looks words starting "page" in k column , shift next column, code using is
public sub loop_through_folder_page_no() 'declare , set variables dim wbk workbook dim filename string dim path string path = "c:\xlsfolder\" filename = dir(path & "*.xlsx") '-------------------------------------------- 'open excel files while len(filename) > 0 'if next file exists set wbk = workbooks.open(path & filename) dim k range dim r range set k = intersect(activesheet.usedrange, range("k:k")) each r in k if left(r.text, 4) = "page" r.copy r.offset(0, 1) r.clear end if next r activeworkbook.save wbk.close true filename = dir loop end sub this code giving error cant figure out what's wrong it.
k range , r range, i'm not sure can "for each range in range." if you're trying loop through cells in range k, can try adding .cells end of loop (for each r in k.cells).
Comments
Post a Comment