vba - Generate Excel file to .txt file and do some looping -


i want generate excel file .txt file , looping. example this:

in excel:

a | b | c | d --+---+---+--- 1 | 5 | 9 | 1 | h | u |  

will generate .txt this:

"a", "1" "b", "5" "c", "9" "d", "1" "a", "a" "b", "h" "c", "u" "d", "i" 

edited: coding

private sub commandbutton1_click() dim sfirst string dim ssecond string dim sthird string dim sfourth string dim sfname string dim intfnumber integer dim lheader long dim llastrow long sheet1.activate range("a1").select sheet1     llastrow = .cells(.rows.count, "a").end(xlup).row end  sfname = thisworkbook.path & "\date" & format(now(), "yyyymmddhhmmss") & ".xls"  'get unused file number intfnumber = freefile  'create new file (or overwrite existing one) open sfname output #intfnumber  lheader = 1 llastrow     sheet1         'for header         sfirst = .cells(lheader, 1)         ssecond = .cells(lheader, 2)         sthird = .cells(lheader, 3)         sfourth = .cells(lheader, 4)     end      'write selected data text file     write #intfnumber, sfirst, ssecond , sthird, sfourth next lheader close #intfnumber  msgbox "values sheet '" & sheet1.name & "' written '" & sfname & "' file!", vbinformation  end sub 

but generate this:

"a", "1"  "b", "5"  "c", "9"  "d", "1" 

try this:

'write selected data text file write #intfnumber, "a", sfirst write #intfnumber, "b", ssecond write #intfnumber, "c", sthird write #intfnumber, "d", sfourth 

instead of this:

write #intfnumber, sfirst, ssecond , sthird, sfourth 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -