excel - VBA TextBox pass value of each line to cell range -


a user pastes values spreadsheet multiline textbox. textbox (tab delimited default):

textbox

so each line has 3 values, sku, qty, price separated 2 tabs in between. (sometimes values of qty or price may omitted).

now trying pass each value of each line 3 dedicated cells, j1 k1 , l1.

final result should image below. (cells overwritten values of next line)

results

code have far successful in passing values of each line msgbox.

sub passvaluestocell()          userform1.textbox25.setfocus     lines = userform1.textbox25.linecount     = 0 lines - 1         msgbox split(userform1.textbox25, chr(13))(i)     next  end sub 

how rework code pass values j1 k1 l1? tried bus errored out

 sub passmultiskutocell()  dim a() string      userform1.textbox25.setfocus     lines = userform1.textbox25.linecount     = 0 lines - 1         a() = split(userform1.textbox25, chr(13))(i)         range("j1").resize(ubound(a) + 1, 1).value = a()     next   end sub 

no need use setfocus , linecount; can number of lines first splitting vblf, split each line vbtab. try this:

sub passvaluestocell()     dim lines: lines = split(userform1.textbox25.value, vblf)     dim long     = 0 ubound(lines)         sheet1.range("j" & + 1).resize(, 3).value = split(lines(i), vbtab)     next end sub 

p.s. if want overwrite lines on same cells j1 k1 l1 (which failed see reason, well) replace "j" & + 1 "j1".


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -