Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macros to export to txt


dear all,

i had spreadsheet which look like this:
ID info
-- ---
KAS_1 123
KAS_2 345
TAS_2 111

i wish to have a macro which can search through the ID column and group
those with same left 3 characters of ID into one txt file.

example of the content of txt files which i prefer:

KAS.txt
-------
1 having 123
2 having 345


(1,2 here is the character after the underscore of ID)

TAS.txt
-------
2 having 111
(2 here is the character after the underscore of ID)


can anyone help me on this?Thousand thanks


--
ymeyaw
------------------------------------------------------------------------
ymeyaw's Profile: http://www.excelforum.com/member.php...o&userid=34421
View this thread: http://www.excelforum.com/showthread...hreadid=541920

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macros to export to txt


hi ,
Thanks for ur advise. But my problem is, i have thousands of data and i
cant simply using copy and paste.
Below is my script, but still cannot group 3 charaters of id into one
single txt file. I had been working on this for few days...:(


Sub test()

startrow = 2
a = startrow
Do While Not Cells(a, "A") = ""
a = a + 1
Loop
endrow = a - 1


For a = startrow To endrow

id_name=left(Cells(a,"A"),3)
id= (Cells(a, "A"))
info= Cells(a, "B")

Call print_output(id, info,id_name)


Close #1


Next a



Sub print_output(id, info,id_name)

homedir = ThisWorkbook.Path
folder = "my_folder"

outputfile = homedir & "/" & folder & "/" & id_name & ".txt"
Open outputfile For Output As #1

Print #1, & id "is "& " " & info; ""




End Sub


--
ymeyaw
------------------------------------------------------------------------
ymeyaw's Profile: http://www.excelforum.com/member.php...o&userid=34421
View this thread: http://www.excelforum.com/showthread...hreadid=541920

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default macros to export to txt


Try this

'############################################
Option Explicit

Sub test()

Const startrow As Long = 2
Dim a As Long
Dim id_name As String, id As String, info As String
Dim temp As String


a = startrow
Do While Not ActiveSheet.Cells(a, "A").Value = ""
temp = ActiveSheet.Cells(a, "A").Value
id_name = Left(temp, 3)
id = Right(temp, Len(temp) - 4)
info = ActiveSheet.Cells(a, "B").Value

Call print_output(id, info, id_name)

a = a + 1
Loop

End Sub




Sub print_output(id, info, id_name)

Dim sPath As String

sPath = ThisWorkbook.Path & "/Test/" & id_name & ".txt"
'note use of append: "for output" will
' always overwrite the last item....
Open sPath For Append As #1
Print #1, id & " is " & info
Close #1
End Sub
'#########################################

Tim


"ymeyaw" wrote in message
...

hi ,
Thanks for ur advise. But my problem is, i have thousands of data and i
cant simply using copy and paste.
Below is my script, but still cannot group 3 charaters of id into one
single txt file. I had been working on this for few days...:(


Sub test()

startrow = 2
a = startrow
Do While Not Cells(a, "A") = ""
a = a + 1
Loop
endrow = a - 1


For a = startrow To endrow

id_name=left(Cells(a,"A"),3)
id= (Cells(a, "A"))
info= Cells(a, "B")

Call print_output(id, info,id_name)


Close #1


Next a



Sub print_output(id, info,id_name)

homedir = ThisWorkbook.Path
folder = "my_folder"

outputfile = homedir & "/" & folder & "/" & id_name & ".txt"
Open outputfile For Output As #1

Print #1, & id "is "& " " & info; ""




End Sub


--
ymeyaw
------------------------------------------------------------------------
ymeyaw's Profile: http://www.excelforum.com/member.php...o&userid=34421
View this thread: http://www.excelforum.com/showthread...hreadid=541920



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macros to export to txt


hi tim,

Thanks for ur greatest help.This is exactly what i want.

I just realized that i have to insert statements in first few lines of
the txt file .So, i do a print action, but the result is poor. Do i need
a reference template (with statement) or i can just write inside the
code?

note: the statement is the same for all the txt files.

example of txt file which i wish to optimise:

KAS.txt
--------
hello world 1
hello world 2
1 is 123
2 is 345


--
ymeyaw
------------------------------------------------------------------------
ymeyaw's Profile: http://www.excelforum.com/member.php...o&userid=34421
View this thread: http://www.excelforum.com/showthread...hreadid=541920



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macros to export to txt


sorry ,

The output in txt which i would like to have:

KAS.txt
--------
Hello world 1
1 having 123
2 having 345
Hello world 2


--
ymeyaw
------------------------------------------------------------------------
ymeyaw's Profile: http://www.excelforum.com/member.php...o&userid=34421
View this thread: http://www.excelforum.com/showthread...hreadid=541920

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import/export excel macros between two computers mick Excel Discussion (Misc queries) 3 May 13th 08 11:40 AM
Export/Inport Macros Tail Wind Excel Discussion (Misc queries) 2 January 5th 08 07:25 PM
export macros Ruben Mikkelsen Excel Programming 9 January 9th 05 07:01 PM
Chip Pearson Import/Export Macros saturnin02[_2_] Excel Programming 21 April 4th 04 11:56 PM
Export Personal Macros Lippy Excel Programming 1 November 10th 03 08:14 PM


All times are GMT +1. The time now is 08:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"