Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Unable to correct VBA code

You can get that type mismatch error if the cell contains an error (like #value!
or #n/a!).

Using the .text property is one way around that error.

So I'm guessing that you're converting formulas that evaluate to "Yes" to
values.



cliff18 wrote:

You blokes are good!
Every bit of that info improved it but Dave nailed it with stopping it
recalculating, so it no longer stresses the CPU.
The only problem I have left is when I open the application I get (below)

Run-time error '13'
Type Mismatch

I hit debug and it highlights the line in dave's code (below)

If i.Value = "Yes" Then

I can stop the debugger and close the VBA and it seems to work fine, but I
guess there is still something not quite right. I'm really pleased to get it
to work but am wondering if anyone can guide me through this last small
obsticale.
Again thanks everyone for your assistance!! I doubted we could have got it
this far.

--
Cheers
cliff18

"Dave Peterson" wrote:

I'm not sure what you're doing or why you're doing this, but each time you make
a change to one of those cells, you could be causing a recalculation.

And every recalculation will cause the event to fire again. So your code could
be running hundreds/thousands of times.

You may want to stop that recursion by using something like:

Option Explicit
Private Sub Worksheet_Calculate()

Dim c As Range
Dim i As Range

Set c = Range("M7:M20")

For Each i In c.Cells
If i.Value = "Yes" Then
Application.EnableEvents = False
i.Value = i.Value
Application.EnableEvents = True
End If
Next i

End Sub



cliff18 wrote:

I had the following code in a VBA which, when I opened the Workbook showed
Error '13' - Type mismatch, I believe relating to the Set c =
Range("M7:M20") line. I exited the error and it would function ok.

Private Sub Worksheet_Calculate()
Set c = Range("M7:M20")
For Each i In c
If i.Value = "Yes" Then
i.Value = i.Value
End If
Next
End Sub

But now, the line in the code has changed itself back to

Set c = Range("M7")

which was the range we had in an earlier code, and obviously only works on
cell M7. I can change the "M7" to "M8" etc, but as soon as I try to change
the range back to ("M7:M20") as I need it, Excel and the VBA freeze.
Does anyone know how I may overcome this?
--
Cheers
cliff18


--

Dave Peterson


--

Dave Peterson
Reply
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
how do I correct a "run time error 1004-unable to open" problem? BillR Excel Programming 1 August 26th 08 07:21 PM
Unable to get a correct total when changing data within a formula JMac Excel Worksheet Functions 2 January 3rd 08 08:43 PM
Please correct for me this code Freeman_100[_5_] Excel Programming 1 April 11th 06 08:37 PM
Please correct for me this code Freeman_100[_6_] Excel Programming 0 April 11th 06 08:03 PM
Please Help Correct my code saziz[_39_] Excel Programming 16 December 16th 05 01:24 AM


All times are GMT +1. The time now is 11:15 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"