How to join these two VBA codes

Aretradeser

Board Regular
Joined
Jan 16, 2013
Messages
176
Office Version
  1. 2013
Platform
  1. Windows
I use 2 codes that work perfectly separately; but when I join them, using the "Call" instruction, it doesn't work, and I don't understand why. So I ask you how to join these codes.

VBA Code:
'
Sub DeleteRows()
'Call IncluirDatosCopiadosCP    ' It does not work
Application.ScreenUpdating = False
Dim rng As Range
Dim InputRng As Range
Dim DeleteRng As Range
Dim DeleteStr As String
xTitleId = "Eliminar Jubilados"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
DeleteStr = Application.InputBox("Delete Text", xTitleId, Type:=2)
For Each rng In InputRng
        If rng.Value = DeleteStr Then
        If DeleteRng Is Nothing Then
            Set DeleteRng = rng
        Else
            Set DeleteRng = Application.Union(DeleteRng, rng)
        End If
    End If
Next
DeleteRng.EntireRow.Delete
Application.ScreenUpdating = True
End Sub
'
Sub IncluirDatosCopiadosCP()
    Application.ScreenUpdating = False
    Sheets("Delegacion").Select
    Range("Delegados").Select
    Selection.Copy
    Sheets("DelegacionA").Select
    Range("B2").Select
    ActiveSheet.Paste
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
When you say it does not work, you mean it doesnt call it?

Looks like you are just copying named ranges

i would say the below would suffice for your bottom macro?

see edit

VBA Code:
Sub IncluirDatosCopiadosCP()
    Range("DelegacionA") = Range("Delegacion")
End Sub
 
Upvote 0
How about
VBA Code:
Sub IncluirDatosCopiadosCP()
    Application.ScreenUpdating = False
    Sheets("Delegacion").Range("Delegados").Copy Sheets("DelegacionA").Range("B2")
End Sub
If that doesn't work, you will need to explain in what way it didn't work.
 
Upvote 0
Solution
How about
VBA Code:
Sub IncluirDatosCopiadosCP()
    Application.ScreenUpdating = False
    Sheets("Delegacion").Range("Delegados").Copy Sheets("DelegacionA").Range("B2")
End Sub
If that doesn't work, you will need to explain in what way it didn't work.
Thank you for your work and good response
 
Upvote 0
When you say it does not work, you mean it doesnt call it?

Looks like you are just copying named ranges

i would say the below would suffice for your bottom macro?

see edit

VBA Code:
Sub IncluirDatosCopiadosCP()
    Range("DelegacionA") = Range("Delegacion")
End Sub
for your work and response
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,991
Members
449,094
Latest member
masterms

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