[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Target.Value Runtime Error

Posted on 2014-01-17
6
Medium Priority
?
216 Views
Last Modified: 2014-01-23
I recently upgraded to Excell 2010 from Excell 2003 and I am getting a runtime error in the 2010 workbook on VBA code that works fine in the 2003 workbook. The error occurs at the Target.Value line of the following:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 8 And Target.Row = 25 Then
temp = Target.Value
For AB = 66 To 7000
If InStr(1, temp, Cells(AB, 29).Value) Then
Target.Value = Cells(AB, 28).Value
Exit For
End If
Next
End If

Any clues on what to do? I have tried to add DoEvents at the beginning of the statement with no luck.
0
Comment
Question by:castlerj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39790490
Hi,

pls try

If Target.Address = "$H$25" Then
    temp = Target.Value
    For AB = 66 To 7000
        If InStr(1, temp, Cells(AB, 29).Value) Then
            Application.EnableEvents = False
            Range(Target.Address).Value = Cells(AB, 28).Value
            Application.EnableEvents = True
            Exit For
        End If
    Next
End If

Open in new window

Regards
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39790497
Can you tell what the error description is?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39790503
For your line:

If InStr(1, temp, Cells(AB, 29).Value) Then

Try

If InStr(1, temp, Cells(AB, 29).Value) > 0 Then

Chris
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 49

Expert Comment

by:Martin Liss
ID: 39790647
Your code works fine for me in Excel 2010 using some simple data that I made up. Can you post the actual workbook, or a sample workbook that illustrates the problem?
0
 
LVL 14

Expert Comment

by:Faustulus
ID: 39793349
Look for the problem in the data types. The Instr function handles Strings. Temp, since it is not dimensioned, is a Variant. There is no guarantee that the value assigned to it will be  a String.. Similarly, Cells(AB, 29).Value is a Variant without assurance of its being of VarType(vbString). So, there is a great chance of comparing apples with oranges.
Start by defining the types of your variables.
Dim Temp As String
Dim AB As Long
Then convert Cells(AB, 29).Value into a String before processing it in the Instr function.
If Instr(1, Temp, CStr(Cells(AB, 29).Value)) Then

This may not cure your problem because between row 66 and row 7000 a lot of different values are assigned to Temp, and only one of these may cause the problem. The difference you will find is that the error message will be more specific. Most important, when an error occurs press the Debug button in the message box and look at the highlighted line of code. Also hover your cursor over the variable AB. This will display its current value, pointing you, in fact, at the cell that is at the source of the error.
0
 

Author Comment

by:castlerj
ID: 39804117
I have been traveling and unable to try your solutions...Thank Uou all...I will try them today...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a serious pitfall that can happen when deleting shapes using VBA.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question