Oneindige loop

HV_L

New Member
Joined
Dec 4, 2009
Messages
43
Hoi,
Ik wil op een sheet zodra er ergens een waarde wordt aangepast (tekst in dit geval) dat de macro IF_Loop runt.
De macro zelf doet het goed (al zoek ik nog naar als er geen text staat (die verwijderd wordt bijv) de cel dan weer gewoon zonder opmaak wordt.

Zodra ik echter de Worksheet_Change erbij haal, schiet Excel in de stress en krijg ik een geen stack ruimte error en crasht de boel..
Wie helpt me het laatste stukje goed te krijgen?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)    If Not Intersect(Target, Me.Range("TestRange")) Is Nothing Then
        Call IF_Loop
    End If
End Sub

Macro IF_Loop
Code:
Sub IF_Loop()    
    Dim cell As Range
    For Each cell In Range("Testrange")
        If (cell.Value = "a") Or (cell.Value = "A") Then
            cell.Value = "A"
            cell.Interior.Color = 15773696
            cell.Font.Color = vbWhite
            cell.Font.Size = 12
            cell.Font.Bold = True
        ElseIf (cell.Value = "Jo") Or (cell.Value = "jo") Then
            cell.Value = "Jo"
            cell.Interior.Color = 49407
            cell.Font.Size = 12
            cell.Font.Bold = True


        End If


    Next cell
End Sub
 
Have a test ... with the following macro ...(some tiny changes ...)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("TestRange")) Is Nothing Then Exit Sub
Dim lLoop As Long
Dim rFoundCell As Range
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' TEST : Dealing ONLY with the "Thea" Case ''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  Application.EnableEvents = False
      If UCase(CStr(Target)) = "THEA" Then
         Target.Value = WorksheetFunction.Proper(Target.Value)
          With Me.Range("TestRange")
            Set rFoundCell = .Cells(1, 1)
                For lLoop = 1 To WorksheetFunction.CountIf(.Cells, Target.Value)
                Set rFoundCell = .Find(What:=Target.Value, After:=rFoundCell, _
                    LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, MatchCase:=False)
                    ' Adjust the specifics
                     With rFoundCell
                        .Interior.Color = 15773696
                        .Font.Color = vbWhite
                        .Font.Size = 12
                        .Font.Bold = True
                     End With
                Next lLoop
          End With
      End If
  Application.EnableEvents = True
End Sub
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top