Notifications
Clear all

Copiar e Colar da Plan1 para a plan2 via VBA

4 Posts
1 Usuários
0 Reactions
1,139 Visualizações
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Bom dia !

Já pesquisei na biblioteca só que eu não consegui realizar o que desejo.

Gostaria de copiar e colar especial valores da plan1 das colunas B:C - iniciando em B15 e C15 até o ultimo dado da coluna B:C.

para a plan2 colar em B15 e C15.

att,
frs

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 30/05/2013 7:07 am
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Bom dia!!

Faça os testes

Sub CopyAleVBA_8297()
    Worksheets("Plan1").Range("B15:C1000").Copy Worksheets("Plan2").Range("B" & Rows.Count).End(xlUp).Offset(15)
End Sub

Att

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 30/05/2013 7:37 am
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Alexandre, ficou perfeito valeu !!!!

obrigado,
frs

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 30/05/2013 7:50 am
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Bom dia!!

Obrigado pelo retorno!!! ;)

Caso queir aprender mais sobre o assunto, aprenda com uma das maiores feras do excel (ron debruin_MVP)
http://www.rondebruin.nl/win/s3/win001.htm

Veja seu código daptado.

Sub AleVBA_Adaptado()
    Dim smallrng As Range, DestRange As Range
    Dim DestSheet As Worksheet, Lr As Long
    Dim SourceRange As Range, I As Integer

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    'fill in the Source Sheet and range
    Set SourceRange = Sheets("Sheet1").Range("B15:C1000")

    'Fill in the destination sheet and call the LastRow
    'function to find the last row
    Set DestSheet = Sheets("Sheet2")
    Lr = LastRow(DestSheet)
    I = 2

    For Each smallrng In SourceRange.Areas

        'We make DestRange the same size as smallrng and use the
        'Value property to give DestRange the same values
        With smallrng
            Set DestRange = DestSheet.Cells(Lr + 1, I) _
                            .Resize(.Rows.Count, .Columns.Count)
        End With
        DestRange.Value = smallrng.Value
        I = I + smallrng.Columns.Count

    Next smallrng

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With

End Sub
Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", _
                            After:=sh.Range("A1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Row
    On Error GoTo 0
End Function
Function LastCol(sh As Worksheet)
    On Error Resume Next
    LastCol = sh.Cells.Find(What:="*", _
                            After:=sh.Range("B1"), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByColumns, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=False).Column
    On Error GoTo 0
End Function

Att

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 30/05/2013 8:13 am