Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A `.split()` function for excel—assumes 0 index, "-" delimiter, and reference cell "A2" but are all customizable. Outputs a string representation of the formula
def recurse(remaining_steps, delimiter='"-"', reference_cell="A2"):
if remaining_steps==0:
return 'SEARCH('+delimiter+','+reference_cell+')+1'
else:
return 'SEARCH('+delimiter+','+reference_cell+','+recurse(remaining_steps-1, delimiter, reference_cell)+')+1'
def build(i, delimiter='"-"', reference_cell="A2"):
if i<0:
raise ValueError
elif i==0:
return 'LEFT('+reference_cell+', SEARCH('+delimiter+','+reference_cell+')-1)'
elif i>=1:
return 'MID('+reference_cell+', '+recurse(i-1,delimiter,reference_cell)+', '+
recurse(i,delimiter,reference_cell)[:-2]+"-"+
recurse(i-1,delimiter,reference_cell)[:-2]+'-1)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment