+ Reply to Thread
Results 1 to 3 of 3

Macro for COPY and PAST RANGE of data to ANOTHER workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    07-13-2012
    Location
    Latvia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro for COPY and PAST RANGE of data to ANOTHER workbook

    Hello,

    I wanted to make macro for copy and past range of data to another workbook. Problem is that range need to change! I have tryed to use code:
    Dim active_sheet As Long
    Dim new_wb As Workbook
    Dim iRow As Long
    Dim oWbk As Workbook
    Dim nWbk As Workbook
    Dim nWst As Worksheet
    
    Set oWbk = ActiveWorkbook
    Set nWbk = Workbooks.Add()
    active_sheet = oWbk.ActiveSheet.Index
    
    For iRow = 27 To r 'nuo 27 eilutes
            val = oWbk.Sheets.Item(active_sheet).Cells(iRow, 6)
            'MsgBox val
            If val = "" Then
                MsgBox "ALL DONE!!!"
                Exit For
            End If
    
    nWst.Cells.Range("j16:br16") = oWbk.Sheets.Item(active_sheet).Range("z27:ch27").Value
    nWst.Cells.Range("Q22") = oWbk.Sheets.Item(active_sheet).Cells(iRow, "DC")
    nWst.Cells.Range("Q23") = oWbk.Sheets.Item(active_sheet).Cells(iRow + 2, "DC")
    Next iRow
    there is more of the code but no need to copy all! this code works without problems but if i try to change line
    nWst.Cells.Range("j16:br16") = oWbk.Sheets.Item(active_sheet).Range("z27:ch27").Value
    to
    nWst.Cells.Range("j16:br16") = oWbk.Sheets.Item(active_sheet).Range("z(iRow):ch(iRow)").Value
    there is error

    Please help me!
    Last edited by Atoms; 07-16-2012 at 02:38 AM. Reason: Code

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro for COPY and PAST RANGE of data to ANOTHER workbook

    That would be:
    nWst.Cells.Range("j16:br16") = oWbk.Sheets.Item(active_sheet).Range("z" & iRow & ":ch" & iRow).Value
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    07-13-2012
    Location
    Latvia
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro for COPY and PAST RANGE of data to ANOTHER workbook

    Tnx it works!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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