How to copy paste destination without using activate sheet

psureck

New Member
Joined
Apr 17, 2014
Messages
3
Hi, I'm having a problem with my macro, I run it from one sheet(A) and I need to copy cells from sheet(B) and paste it to sheet(C) but I could only make it changing sheets, there is any way to do that without activate sheets???

My macro:

Code:
Sub VPL()

Dim j As Long, i As Long




For j = 1 To 9


' COPIAR/COLAR GERAÇÃO


[COLOR=#ff0000]' How to do this without activate sheets "Geração" and "Premissas"????[/COLOR]

Sheets("Geração").Activate
ActiveSheet.Range(Cells(20, 2 + j), Cells(31, 2 + j)).Select
Selection.Copy


Sheets("Premissas").Activate
ActiveSheet.Range("Z20:AI31").Select
 Selection.PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, _
    SkipBlanks:=False, _
    Transpose:=False


Sheets("Premissas").Activate
ActiveSheet.Range("AL20:AL31").Select
 Selection.PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, _
    SkipBlanks:=False, _
    Transpose:=False




' COPIAR/COLAR PLD


    For i = 1 To 2000

[COLOR=#ff0000]'The same problem here.[/COLOR]


Sheets("PLD NE").Activate
ActiveSheet.Range(Cells(1 + i, 1), Cells(1 + i, 60)).Select
Selection.Copy


Sheets("Macro").Activate
ActiveSheet.Range("AZ27").Select
 Selection.PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, _
    SkipBlanks:=False, _
    Transpose:=False




'COPIAR/COLAR VPL
[COLOR=#ff0000]
'The macro runs form Sheets("RESULTADO LEN") and I want only to be on this sheet.[/COLOR]


Sheets("RESULTADO LEN").Activate


Sheets(10).Cells(3 + i, 2 + j) = Sheets(5).Cells(35, 4).Value   'Ametista
Sheets(10).Cells(3 + i, 11 + j) = Sheets(5).Cells(62, 4).Value  'Borgo
Sheets(10).Cells(3 + i, 20 + j) = Sheets(5).Cells(89, 4).Value  'Caitite
Sheets(10).Cells(3 + i, 29 + j) = Sheets(5).Cells(116, 4).Value 'Dourados
Sheets(10).Cells(3 + i, 38 + j) = Sheets(5).Cells(143, 4).Value 'Espigão
Sheets(10).Cells(3 + i, 47 + j) = Sheets(5).Cells(170, 4).Value 'Maron
Sheets(10).Cells(3 + i, 56 + j) = Sheets(5).Cells(197, 4).Value 'Pelourinho
Sheets(10).Cells(3 + i, 65 + j) = Sheets(5).Cells(224, 4).Value 'Pilões
Sheets(10).Cells(3 + i, 74 + j) = Sheets(5).Cells(251, 4).Value 'Serra do espigão
Sheets(10).Cells(3 + i, 83 + j) = Sheets(6).Cells(36, 4).Value  'São Salvador


Next
Next


End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I tried to solve this problem with the code below, but this way is very very slow

Code:
' VPL Macro

Sub VPLteste()


Dim j As Long, i As Long


' COPIAR/COLAR GERAÇÃO


For j = 1 To 9


    For x = 1 To 12
    For y = 1 To 10
    
        Sheets("Premissas").Cells(19 + x, 25 + y) = Sheets("Geração").Cells(19 + x, 2 + j)
        Sheets("Premissas").Cells(19 + x, 38) = Sheets("Geração").Cells(19 + x, 2 + j)
    
    Next
    Next


 
' COPIAR/COLAR PLD


    For i = 1 To 2000
            
        For Z = 1 To 60
        
            Sheets("Macro").Cells(27, 51 + Z) = Sheets("PLD NE").Cells(1 + i, Z)
                
        Next






'COPIAR/COLAR VPL


Sheets("RESULTADO LEN").Activate


Sheets(10).Cells(3 + i, 2 + j) = Sheets(5).Cells(35, 4).Value   'Ametista
Sheets(10).Cells(3 + i, 11 + j) = Sheets(5).Cells(62, 4).Value  'Borgo
Sheets(10).Cells(3 + i, 20 + j) = Sheets(5).Cells(89, 4).Value  'Caitite
Sheets(10).Cells(3 + i, 29 + j) = Sheets(5).Cells(116, 4).Value 'Dourados
Sheets(10).Cells(3 + i, 38 + j) = Sheets(5).Cells(143, 4).Value 'Espigão
Sheets(10).Cells(3 + i, 47 + j) = Sheets(5).Cells(170, 4).Value 'Maron
Sheets(10).Cells(3 + i, 56 + j) = Sheets(5).Cells(197, 4).Value 'Pelourinho
Sheets(10).Cells(3 + i, 65 + j) = Sheets(5).Cells(224, 4).Value 'Pilões
Sheets(10).Cells(3 + i, 74 + j) = Sheets(5).Cells(251, 4).Value 'Serra do espigão
Sheets(10).Cells(3 + i, 83 + j) = Sheets(6).Cells(36, 4).Value  'São Salvador


Next
Next


End Sub
 
Upvote 0
Since you only want to copy values, you don't need to activate sheets, or select ranges or even copy/paste. Instead you can simply do this (example for your first two "pastes"):

Code:
With Sheets("Premissas")
    .Range("Z20:AI31").Value = Sheets("Geração").Range(Cells(20, 2 + j), Cells(31, 2 + j)).Value
    .Range("AL20:AL31").Value = Sheets("Geração").Range(Cells(20, 2 + j), Cells(31, 2 + j)).Value
End With
 
Upvote 0
Since you only want to copy values, you don't need to activate sheets, or select ranges or even copy/paste. Instead you can simply do this (example for your first two "pastes"):

Code:
With Sheets("Premissas")
    .Range("Z20:AI31").Value = Sheets("Geração").Range(Cells(20, 2 + j), Cells(31, 2 + j)).Value
    .Range("AL20:AL31").Value = Sheets("Geração").Range(Cells(20, 2 + j), Cells(31, 2 + j)).Value
End With


Didn't work this way.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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