LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Insert line in a text file between 3rd and 4th lines

First import your data into column A of a worksheet. Then run:

Sub rules()
s1 = "aaaaa"
s2 = "pppp"
s3 = "yyyy"
s4 = "xxxxx"
s5 = "qqqq"
n = Cells(Rows.Count, 1).End(xlUp).Row
For i = n To 1 Step -1
With Cells(i, 1)
v = .Value
If v = s3 Then
.Delete Shift:=xlUp
Else
If v = s2 Then
.Value = s5
End If
End If
End With
Next

n = Cells(Rows.Count, 1).End(xlUp).Row
For i = n To 1 Step -1
With Cells(i, 1)
v = .Value
If v = s1 Then
.Offset(1, 0).Insert Shift:=xlDown
End If
End With
Next

n = Cells(Rows.Count, 1).End(xlUp).Row
For i = n To 1 Step -1
With Cells(i, 1)
v = .Value
If v = s1 Then
.Offset(1, 0).Value = s4
End If
End With
Next
End Sub


Then save. So data like:
aaaaa
pppp
pppp
aaaaa
aaaaa
yyyy
yyyy
pppp
aaaaa
aaaaa
yyyy
pppp
aaaaa
aaaaa
yyyy
aaaaa
yyyy
aaaaa
yyyy
yyyy

will become:
aaaaa
xxxxx
qqqq
qqqq
aaaaa
xxxxx
aaaaa
xxxxx
qqqq
aaaaa
xxxxx
aaaaa
xxxxx
qqqq
aaaaa
xxxxx
aaaaa
xxxxx
aaaaa
xxxxx
aaaaa
xxxxx



--
Gary''s Student - gsnu2007L


"Sri via OfficeKB.com" wrote:

Hello all,

I have few thousands of XML messages which I need to convert according to new
specs. This means,

Rule 1: I should insert a line with text "xxxxx" immediately after I see a
line with text "aaaaa".

Rule 2: I shoud delete all lines with test "yyyy".

Rule 3: I should replace "pppp" with "qqqq" etc..etc...

I am planing to write a small VB macro in XL to which I give my XML folder as
input. This macro should read each file and apply few rules as mentioned
above and save the file. Any help in this regard please... how to achieve
rule 1, rule 2 and rule 3.

I am only aware of WriteLine method with which we can only APPEND the line.

Sri

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200902/1


 
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
Insert line in first row of CSV text file with VBA JA[_4_] Excel Programming 1 July 16th 08 09:34 PM
Is there a way to skip lines (insert value every other line) Mike Excel Programming 3 May 21st 08 08:36 PM
Insert line every x lines until end of data tiger Excel Programming 4 August 14th 07 04:45 AM
macro to insert blank line when lines sum to zero TCoats Excel Discussion (Misc queries) 0 July 2nd 07 05:08 PM
Read a .xls file and insert its values to certain lines in a text Thegman Excel Programming 2 December 5th 05 04:11 PM


All times are GMT +1. The time now is 02:08 AM.

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"