PC Review


Reply
Thread Tools Rate Thread

Combine macros mismatch

 
 
amelia
Guest
Posts: n/a
 
      15th Feb 2009
I try combining the 2 macros below into 1 in the same sheet, the codes shown.
But I was prompted error below---
Run-time error '13':Type mismatch

Sub CallMacros()
Call ButtonReset_Click
Call Worksheet_Calculate
End Sub


Private Sub Worksheet_Calculate()
Dim r As Range
Set r = Range("E65")
If r = "pop" Then Msg = MsgBox("Joint capacity is insufficient.Re-select a
bigger section size.", vbExclamation + vbOKOnly, "Rectangular Hollow Section")

End Sub

Sub ButtonReset_Click()
If MsgBox("Are you sure you want to permanently delete the data?", _
vbQuestion + vbYesNo + vbDefaultButton, "Rectangular Hollow Section") = vbNo
Then Exit Sub
For Each cell In ActiveSheet.UsedRange
If cell.Interior.ColorIndex = 20 Then
cell.Formula = ""
End If
Next cell
End Sub


Appreciate any help on where I went wrong. Thanks.
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      15th Feb 2009
I think I would do it like this. If I wanted the worksheet_calculate to
checkr then just call it from there.

Sub combineem()
Call ButtonReset_Click
Call checkr
End Sub

Sub ButtonReset_Click()
If MsgBox("Are you sure you want to permanently delete the data?", _
vbQuestion + vbYesNo + vbDefaultButton, "Rectangular Hollow Section") _
= vbNo Then Exit Sub

For Each c In ActiveSheet.UsedRange
If c.Interior.ColorIndex = 20 Then
c.ClearContents
End If
Next c
End Sub

Sub checkr()
Dim r As Range
Set r = Range("b1")
If lcase(r) = "pop" Then _
MsgBox "Joint capacity is insufficient.Re-select a bigger section size.", _
vbExclamation + vbOKOnly, "Rectangular Hollow Section"
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"amelia" <(E-Mail Removed)> wrote in message
news:A652007B-6A3A-4C10-BBF4-(E-Mail Removed)...
>I try combining the 2 macros below into 1 in the same sheet, the codes
>shown.
> But I was prompted error below---
> Run-time error '13':Type mismatch
>
> Sub CallMacros()
> Call ButtonReset_Click
> Call Worksheet_Calculate
> End Sub
>
>
> Private Sub Worksheet_Calculate()
> Dim r As Range
> Set r = Range("E65")
> If r = "pop" Then Msg = MsgBox("Joint capacity is insufficient.Re-select a
> bigger section size.", vbExclamation + vbOKOnly, "Rectangular Hollow
> Section")
>
> End Sub
>
> Sub ButtonReset_Click()
> If MsgBox("Are you sure you want to permanently delete the data?", _
> vbQuestion + vbYesNo + vbDefaultButton, "Rectangular Hollow Section") =
> vbNo
> Then Exit Sub
> For Each cell In ActiveSheet.UsedRange
> If cell.Interior.ColorIndex = 20 Then
> cell.Formula = ""
> End If
> Next cell
> End Sub
>
>
> Appreciate any help on where I went wrong. Thanks.


 
Reply With Quote
 
amelia
Guest
Posts: n/a
 
      15th Feb 2009
Ive tried like you suggested--Sub checkr().
But the message box doesn't appear when cell E65="pop" and was prompted a
mismatch error. Cell E65 is dependent on some other cells that caused E65 to
change to "pop".

My previous code..
I was also prompted a mismatch error and this is highlighted--If r = "pop"
Then.

Appreciate any help..

"Don Guillett" wrote:

> I think I would do it like this. If I wanted the worksheet_calculate to
> checkr then just call it from there.
>
> Sub combineem()
> Call ButtonReset_Click
> Call checkr
> End Sub
>
> Sub ButtonReset_Click()
> If MsgBox("Are you sure you want to permanently delete the data?", _
> vbQuestion + vbYesNo + vbDefaultButton, "Rectangular Hollow Section") _
> = vbNo Then Exit Sub
>
> For Each c In ActiveSheet.UsedRange
> If c.Interior.ColorIndex = 20 Then
> c.ClearContents
> End If
> Next c
> End Sub
>
> Sub checkr()
> Dim r As Range
> Set r = Range("b1")
> If lcase(r) = "pop" Then _
> MsgBox "Joint capacity is insufficient.Re-select a bigger section size.", _
> vbExclamation + vbOKOnly, "Rectangular Hollow Section"
> End Sub
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "amelia" <(E-Mail Removed)> wrote in message
> news:A652007B-6A3A-4C10-BBF4-(E-Mail Removed)...
> >I try combining the 2 macros below into 1 in the same sheet, the codes
> >shown.
> > But I was prompted error below---
> > Run-time error '13':Type mismatch
> >
> > Sub CallMacros()
> > Call ButtonReset_Click
> > Call Worksheet_Calculate
> > End Sub
> >
> >
> > Private Sub Worksheet_Calculate()
> > Dim r As Range
> > Set r = Range("E65")
> > If r = "pop" Then Msg = MsgBox("Joint capacity is insufficient.Re-select a
> > bigger section size.", vbExclamation + vbOKOnly, "Rectangular Hollow
> > Section")
> >
> > End Sub
> >
> > Sub ButtonReset_Click()
> > If MsgBox("Are you sure you want to permanently delete the data?", _
> > vbQuestion + vbYesNo + vbDefaultButton, "Rectangular Hollow Section") =
> > vbNo
> > Then Exit Sub
> > For Each cell In ActiveSheet.UsedRange
> > If cell.Interior.ColorIndex = 20 Then
> > cell.Formula = ""
> > End If
> > Next cell
> > End Sub
> >
> >
> > Appreciate any help on where I went wrong. Thanks.

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Combine Macros LiAD Microsoft Excel Programming 2 27th Apr 2009 06:45 PM
Combine 3 Macros LiAD Microsoft Excel Programming 4 22nd Apr 2009 07:37 AM
Combine Macros Dorci Microsoft Powerpoint 2 22nd Sep 2008 09:28 PM
COMBINE TWO MACROS INTO ONE K Microsoft Excel Programming 10 4th Jan 2008 01:48 PM
combine two macros =?Utf-8?B?TGlzYQ==?= Microsoft Excel Worksheet Functions 1 20th Jul 2006 02:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:27 PM.