LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Reusing code

Hi Blee,
Try this instead.
As you can see there is nothing actually hard coded, its is all done
through the constants.
You can add as many failure codes as you want.
Also, this wont loop through all the cells in the colum.

Kind regards
Bernie Russell

----------------------------------------------------------------------------------
Public Sub Exclusions2()



Const ACTION As String = "Manual"
Const SEARCHPREFIX As String = "Match"
Const REASONPREFIX As String = "Failure Code "
Const OFFSETMANUAL As Integer = -17 'Or whatever offset you want.
Const OFFSETREASON As Integer = -20

Dim FailureCodes() As Variant
FailureCodes = Array("A", "B", "C", "D", "E", "F") 'Put in what ever
you want here

Dim fc As String
Dim sCVal As String

Dim i As Integer
Dim rRangeToSearch As Range
'Set rRangeToSearch = ActiveCell.EntireColumn 'Or set it like this
worksheets(1).Range("A:A")
With ActiveCell.EntireColumn
' This sets the range to be searched to the first cell in the column
to the last used cell in the column.
' So it wont have to go through 65536 cells. ie This is quicker
Set rRangeToSearch =
Range(.Cells(1), .Cells(.Cells.Count).End(xlUp))
Debug.Print rRangeToSearch.Address
End With

On Error GoTo Err_Exclusions2
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Dim c As Range
For Each c In rRangeToSearch.Cells
Debug.Print c.Address & " " & c.Value
With c
If Len(.Value) 0 Then
sCVal = UCase(.Value)
For i = LBound(FailureCodes) To UBound(FailureCodes)
fc = UCase(FailureCodes(i))
If InStr(1, sCVal, UCase(SEARCHPREFIX) & fc) 0 And
Len(fc) < 0 Then
.Offset(0, OFFSETREASON).Value = CStr(REASONPREFIX & fc)
.Offset(0, OFFSETMANUAL).Value = ACTION
End If
Next i
End If
End With 'c
Next c

ExitSub:
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
Set c = Nothing
Set rRangeToSearch = Nothing
Exit Sub

Err_Exclusions2:
MsgBox "An error occured in when running the Exclusions2 sub
procedure"
GoTo ExitSub
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 03:59 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"