+ Reply to Thread
Results 1 to 4 of 4

Copy a range form one sheet to a new Workbook (for archive)

Hybrid View

crycx Copy a range form one sheet... 06-12-2013, 04:33 AM
AB33 Re: Copy a range form one... 06-12-2013, 04:40 AM
crycx Re: Copy a range form one... 06-12-2013, 05:11 AM
crycx Re: Copy a range form one... 06-12-2013, 03:53 PM
  1. #1
    Registered User
    Join Date
    05-27-2013
    Location
    Tallinn, Estonia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Copy a range form one sheet to a new Workbook (for archive)

    I have a code, I think i got it from this forum (modified a bit), but i can be wrong.

    The code:

    Private Sub CommandButton1_Click()
      
      Dim DstRng As Range
      Dim Rng As Range
      Dim RngEnd As Range
      Dim SrcRng As Range
      Dim Response As VbMsgBoxResult
      
        Response = MsgBox("Kas oled kindel, et soovid andmed arhiivi salvestada?" & vbCrLf & "(kaasneb väljade tühjendamine)", vbQuestion + vbYesNo Or vbDefaultButton2, "Andmete salvestamine")
        If Response = vbYes Then
        
        With Worksheets("Arhiiv")
          Set Rng = .Range("A2")
          Set RngEnd = .Cells(Rows.Count, Rng.Column).End(xlUp)
          Set DstRng = IIf(RngEnd.Row < Rng.Row, Rng, RngEnd.Offset(2, 0))
        End With
        
        With Worksheets("Eri_fr")
          Set Rng = .Range("soelkover")
          Set SrcRng = Rng
        End With
        
        Set SrcRng = SrcRng.Resize(ColumnSize:=30)
        DstRng.Cells(1, 1).Resize(SrcRng.Rows.Count, SrcRng.Columns.Count) = SrcRng.Value
                 
        MsgBox "Andmete salvestamine arhiivi oli edukas" & vbCrLf & "", vbInformation, "Andmete salvestamine"
    
        Range("andmed").ClearContents
        Range("A4:A5").ClearContents
        Range("kaalud").ClearContents
        
        CheckBox1.Value = False
        
        End If
        
        Range("A4").Select
        
        Set wsArhiiv = Nothing
        Set wsEri_fr = Nothing
        Set rNextCl = Nothing
        
        
        ThisWorkbook.Save
        
    End Sub
    I'm new to VBA. And i would be thankful.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy a range form one sheet to a new Workbook (for archive)

    You do not say what is wrong with the code and which part of the code you want to amend it?

  3. #3
    Registered User
    Join Date
    05-27-2013
    Location
    Tallinn, Estonia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Copy a range form one sheet to a new Workbook (for archive)

    Sorry.

    With Worksheets("Arhiiv")
          Set Rng = .Range("A2")
          Set RngEnd = .Cells(Rows.Count, Rng.Column).End(xlUp)
          Set DstRng = IIf(RngEnd.Row < Rng.Row, Rng, RngEnd.Offset(2, 0))
        End With
    This part needs to be altered, so that the it would save to workbook located in address P:\... and named arhiiv.xlsx

    The code I posted in the first post works great, but i don't have no idea how to get it to do what i need.

  4. #4
    Registered User
    Join Date
    05-27-2013
    Location
    Tallinn, Estonia
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Copy a range form one sheet to a new Workbook (for archive)

    Can I maybe add something like

    With Workbook.("arhiiv.xlsx").Worksheets("Arhiiv")
          Set Rng = .Range("A2")
          Set RngEnd = .Cells(Rows.Count, Rng.Column).End(xlUp)
          Set DstRng = IIf(RngEnd.Row < Rng.Row, Rng, RngEnd.Offset(2, 0))
        End With
    I don't think it works.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1