VB Code Issue

SV18

Board Regular
Joined
Sep 1, 2008
Messages
157
Hi all,

I have the following code which isn't exactly how I want it to. The problem I have is the code is set on the change property of the worksheet, so when lines of the code make a change to a cell the macro tries to run itself again. It's really strange as I've not witnessed anything like this before, can anyone suggest anything?

Private Sub Worksheet_change(ByVal Target As Range)

If Not Intersect(Target, Range("B7:B21")) Is Nothing Then

If Left(Target.Value, 4) = "Tier" Then
ret = InputBox("Enter Investment Name", Left(Target.Value, 6) & " Investment Name")
Else
ret = Target.Value
End If
Target.Offset(0, 2).Value = ret

'Calculate the first Tier 1 fund (needed for the illustration.

Count = 1
Do While Count < 14 'Cycle through the rows and establish which is the first "Tier 1" fund - This will be used as an example on the illustration.
If Cells(Count + 6, 3) = 1 Then
Range("D23").Value = Cells(Count + 6, 4).Value
Range("M23").Value = Cells(Count + 6, 13).Value
Exit Do
End If
Count = Count + 1
Loop

End If
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try

Rich (BB code):
Private Sub Worksheet_change(ByVal Target As Range)

If Not Intersect(Target, Range("B7:B21")) Is Nothing Then
    Application.EnableEvents = False
    If Left(Target.Value, 4) = "Tier" Then
        ret = InputBox("Enter Investment Name", Left(Target.Value, 6) & " Investment Name")
    Else
        ret = Target.Value
    End If
    Target.Offset(0, 2).Value = ret
    
    'Calculate the first Tier 1 fund (needed for the illustration.
    
    Count = 1
    Do While Count < 14 'Cycle through the rows and establish which is the first "Tier 1" fund - This will be used as an example on the illustration.
        If Cells(Count + 6, 3) = 1 Then
            Range("D23").Value = Cells(Count + 6, 4).Value
            Range("M23").Value = Cells(Count + 6, 13).Value
            Exit Do
        End If
        Count = Count + 1
    Loop
    Application.EnableEvents = True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,812
Members
452,945
Latest member
Bib195

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