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: 6
Default Reusing code

I'm searching a column for matches (FindThis) and writing to cells on
the row (WriteReason) on success. The macro below works fine, but my
number of matching terms is increasing and I find myself just copying
and pasting the code over and over again. Is there a better way to
modularize this just plug in values without creating "FindThisA,
FindThisB", etc?

----

Sub Exclusions()

WriteManual = "Manual"

Const FindThisA = "MatchA"
Const WriteReasonA = "Failure Code A"
Const FindThisB = "MatchB"
Const WriteReasonB = "Failure Code B"

Dim A As Range, retA
ActiveCell.EntireColumn.Select
For Each A In Selection
retA = InStr(1, A, FindThisA, vbTextCompare)
If (Not IsNull(retA)) And (retA 0) Then
A.Offset(0, -17).Value = WriteReasonA
A.Offset(0, -20).Value = WriteManual
End If
Next A

Dim B As Range, retB
ActiveCell.EntireColumn.Select
For Each B In Selection
retB = InStr(1, B, FindThisB, vbTextCompare)
If (Not IsNull(retB)) And (retB 0) Then
B.Offset(0, -17).Value = WriteReasonB
B.Offset(0, -20).Value = WriteManual
End If
Next B

End Sub
 
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
reusing code MJKelly Excel Programming 3 August 28th 08 09:55 PM
Reusing Form Code DMc2004 Excel Programming 4 November 16th 07 05:33 PM
Reusing formula Tony29 Excel Discussion (Misc queries) 7 September 7th 06 03:34 AM
Reusing grouping of non-adjacent cells [email protected] Excel Discussion (Misc queries) 2 May 28th 06 01:21 PM
reusing a recordset for a pivot-table? Bart op de grote markt Excel Programming 2 March 7th 06 03:34 PM


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