LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Find and replace, or insert in VBA code

Hi,

I have an update program used to change or add to the code in another
workbook. I have previously used it to correct errors as below;

On Error GoTo thiserror:
With THISBOOK.VBProject.VBComponents.Item("module1").Co deModule

Dim MYCODE
MYCODE = .Lines(1, .CountOfLines)
MYCODE = Replace(MYCODE, "SOUTH", "South")

..DeleteLines 1, .CountOfLines
..InsertLines .CountOfLines + 1, MYCODE

End With

Here it finds the word SOUTH in the code and replaces it with the word
South. However I now wish to make this more complex and am unsure how
to go about it.

I want to find the line -

Next Target

and insert the following code below it -

For Each Target In ActiveSheet.Range("B3:B" & ROWSS + 2)
If Target.Offset(0, 10).Value = "Closed" Then
With Target
.Offset(0, 1).Value = "-1"
.Interior.ColorIndex = 40
.Offset(0, 2).Interior.ColorIndex = 40
.Offset(0, 3).Interior.ColorIndex = 40
.Offset(0, 4).Interior.ColorIndex = 40
.Offset(0, 5).Interior.ColorIndex = 40
.Offset(0, 6).Interior.ColorIndex = 40
.Offset(0, 7).Interior.ColorIndex = 40
.Offset(0, 8).Interior.ColorIndex = 40
.Offset(0, 9).Interior.ColorIndex = 40
.Offset(0, 10).Interior.ColorIndex = 40
.Offset(0, 11).Interior.ColorIndex = 40
.Offset(0, 12).Interior.ColorIndex = 40
.Offset(0, 13).Interior.ColorIndex = 40
.Offset(0, 14).Interior.ColorIndex = 40
.Offset(0, 15).Interior.ColorIndex = 40
End With
Else
If Target.Offset(0, 10).Value = "Duplicate" Then
With Target
.Offset(0, 1).Value = "-1"
.Interior.ColorIndex = 40
.Offset(0, 2).Interior.ColorIndex = 40
.Offset(0, 3).Interior.ColorIndex = 40
.Offset(0, 4).Interior.ColorIndex = 40
.Offset(0, 5).Interior.ColorIndex = 40
.Offset(0, 6).Interior.ColorIndex = 40
.Offset(0, 7).Interior.ColorIndex = 40
.Offset(0, 8).Interior.ColorIndex = 40
.Offset(0, 9).Interior.ColorIndex = 40
.Offset(0, 10).Interior.ColorIndex = 40
.Offset(0, 11).Interior.ColorIndex = 40
.Offset(0, 12).Interior.ColorIndex = 40
.Offset(0, 13).Interior.ColorIndex = 40
.Offset(0, 14).Interior.ColorIndex = 40
.Offset(0, 15).Interior.ColorIndex = 40
End With
End If
End If
Next Target
ActiveSheet.Range("b2:t3000").Select
Selection.sort Key1:=ActiveSheet.Range("C3"), Order1:=xlDescending



But I am unsure where to start.

Many thanks in advance

 
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
Find & Replace and Find & Insert macro help needed RS Excel Programming 2 January 29th 07 07:35 AM
Excel VBA code for find/replace Needles Excel Programming 7 September 19th 06 04:29 PM
Code to modify find/replace mcphc Excel Programming 3 June 30th 06 05:09 PM
Can I use "find / replace" to automatically "Insert Rows" in a do. Dr. Picou Excel Discussion (Misc queries) 2 September 1st 05 09:59 PM
Using code to mimic a find and replace ST Excel Programming 3 March 30th 05 12:52 PM


All times are GMT +1. The time now is 11:59 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"