Solved

Target.Value Runtime Error

Posted on 2014-01-17
6
205 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
6 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 45

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now