none
Copy selected range to another worksheet RRS feed

  • Question

  • Hello to all,

    I'm very new to programming and I'm struggling to solve this problem and could not find the solution. I'm using this code to compare two Excel (2007) Worksheets. Whenever a line on sheet1 is not foud on sheet2 it must be copied to sheet3. Everything  goes fine until the selection of the row on sheet1. My problem is that I don't know how to copy the selected row.
    I tried UsedRange but it selects all data...

    Do While Globals.ThisAddIn.Application.ActiveCell.Text <> ""
                Dim xlSR As Excel.Range
                procurar_por = Globals.ThisAddIn.Application.ActiveCell.Offset(0, 1).Text
                wb.Sheets(2).Activate()
                On Error Resume Next
                wb.Sheets(2).Range("B:B").Find(procurar_por).Select()
                If Err.Number <> 0 Then
                    'c?digo para copiar para f3
                    Clipboard.Clear()
                    On Error GoTo 0
                    wb.Sheets(1).Activate()
                    r = Globals.ThisAddIn.Application.ActiveCell.Row
                    ws.Range(r & ":" & r).Select()
                    'HERE is my problem, the range is selected, how to copy it?
                    cnt = cnt + 1
                    'ws.UsedRange.Copy()
                    'ws.Copy()
                    
                    wb.Sheets(3).Activate()
                    Globals.ThisAddIn.Application.ActiveCell.PasteSpecial(Excel.XlPasteType.xlPasteAll)
                    Globals.ThisAddIn.Application.ActiveCell.Offset(1, 0).Select()
                End If
                wb.Sheets(1).Activate()
                Globals.ThisAddIn.Application.ActiveCell.Offset(1, 0).Select()
            Loop

    Thanks for any kind help.

    Octavio

    Wednesday, December 2, 2015 11:44 AM

Answers

  • The Macro Recorder should give you the answer.

        Range("A1:J20").Select
        Selection.Copy
        Sheets("Sheet2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("A1").Select



    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    • Proposed as answer by David_JunFeng Friday, December 4, 2015 12:56 AM
    • Marked as answer by David_JunFeng Tuesday, December 15, 2015 1:36 AM
    Wednesday, December 2, 2015 5:28 PM

All replies

  • Excel for developers or Visual Basic for applications maybe can help you on VBA code, this forum is for VB.net. If you need VB.net example let us know

    Fouad Roumieh


    Wednesday, December 2, 2015 12:36 PM
  • The Macro Recorder should give you the answer.

        Range("A1:J20").Select
        Selection.Copy
        Sheets("Sheet2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Range("A1").Select



    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    • Proposed as answer by David_JunFeng Friday, December 4, 2015 12:56 AM
    • Marked as answer by David_JunFeng Tuesday, December 15, 2015 1:36 AM
    Wednesday, December 2, 2015 5:28 PM