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
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

adam087

Well-known Member
Joined
Jun 7, 2010
Messages
1,356
What is the routine 'RightClick4' doing?
And where does it error?

/AJ
 

cenky

New Member
Joined
Jul 30, 2014
Messages
10
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
 

cenky

New Member
Joined
Jul 30, 2014
Messages
10

ADVERTISEMENT

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
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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.
 

cenky

New Member
Joined
Jul 30, 2014
Messages
10
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 :(
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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
 

Watch MrExcel Video

Forum statistics

Threads
1,127,853
Messages
5,627,259
Members
416,236
Latest member
Lynchbox

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
Top