More Private Sub dont work together

cenky

New Member
Joined
Jul 30, 2014
Messages
10
Hello I have two Private Sub codes (one for ComboBox and one for rightclick) working properly sepatately. But when they are together, excel publish Run Time error 1004 (it cant copy simple cell and paste it). Will somebody help me?
Here is the code:

Private Sub ComboBox1_Change()

Select Case Range("D45").Value
Case "1dosp"
Úvěr_1
Case "2dosp"
Úvěr_2

Case Else
Exit Sub

End Select

End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
RightClick4
Cancel = True
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
What is the routine 'RightClick4' doing?
And where does it error?

/AJ
RightCLick4 opens menu for three other macros, all work perfect. :
Sub RightClick4()
Dim vArr As Variant, i As Integer
Dim oMenu As CommandBar, oltem As CommandBarControl
Set oMenu = CommandBars.Add("", msoBarPopup, , True)

vArr = Array("Přidat_úvěr", "Přidat_doporučovaný_úvěr", "Odstranit_smlouvu")
For i = 0 To UBound(vArr)
Set oltem = oMenu.Controls.Add
oltem.Caption = vArr(i)
oltem.OnAction = vArr(i)
Next i
oMenu.ShowPopup
End Sub
 
Upvote 0
Sub Úvěr_1()
Sheets("Úvěry").Activate
Range("D42").Select
Selection.Copy
Range("D46").Select
ActiveSheet.Paste
Range("D6").Select
Application.CutCopyMode = False
End Sub
Sub Úvěr_2()
Sheets("Úvěry_2").Activate
Range("D43").Select
Selection.Copy
Range("D46").Select
ActiveSheet.Paste
Range("D6").Select
Application.CutCopyMode = False

End Sub
 
Upvote 0
What's the text of the error?

As an aside, if your code is in a Worksheet module, unqualified properties (like Range) will refer to the worksheet containing the code rather than the ActiveSheet. So D43 on the worksheet containing the code will be copied, not D43 on worksheet Úvěry_2.
 
Upvote 0
What's the text of the error?

As an aside, if your code is in a Worksheet module, unqualified properties (like Range) will refer to the worksheet containing the code rather than the ActiveSheet. So D43 on the worksheet containing the code will be copied, not D43 on worksheet Úvěry_2.

"Run time error 1004: Method Copy Range failed.

I have found out that when delete
" Range("D42").Select
Selection.Copy
Range("D46").Select
ActiveSheet.Paste
Range("D6").Select
Application.CutCopyMode = False "

than it works. But I miss this part :(
 
Upvote 0
Does this work for you?

Code:
Sub Úver_2()
    With Sheets("Úvery_2")
        .Range("D43").Copy .Range("D46")
    End With
    Application.CutCopyMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,413
Messages
6,119,372
Members
448,888
Latest member
Arle8907

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