+ Reply to Thread
Results 1 to 11 of 11

Running Macro to copy Rows of Formulas

Hybrid View

  1. #1
    Registered User
    Join Date
    11-11-2007
    Posts
    44
    Thank you!
    It worked!

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Your welcome

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    11-11-2007
    Posts
    44
    Another Question:

    I have gotten the codes to work, but now I want to copy the info from one worksheet to another worksheet.

    The codes below work but it closes the worksheet automatically rather than keeping it open.

    Sub Copy_To_Another_Workbook()
        Dim SourceRange As Range
        Dim DestRange As Range
        Dim DestWB As Workbook
        Dim DestSh As Worksheet
        Dim Lr As Long
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
        End With
    
        'Change the file name (2*) and the path/file name to your file
        If bIsBookOpen_RB("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls") Then
            Set DestWB = Workbooks("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls")
        Else
            Set DestWB = Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls")
        End If
    
        'Change the Source Sheet and range
        Set SourceRange = ThisWorkbook.Sheets("test1").Range("A1:K1")
        
        'Change the sheet name of the database workbook
        Set DestSh = DestWB.Worksheets("test2")
    
    
        Lr = LastRow(DestSh)
        Set DestRange = DestSh.Range("A" & Lr + 1)
    
        'We make DestRange the same size as SourceRange and use the Value
        'property to give DestRange the same values
        With SourceRange
            Set DestRange = DestRange.Resize(.Rows.Count, .Columns.Count)
        End With
        DestRange.Value = SourceRange.Value
    
        DestWB.Close savechanges:=True
    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
        End With
    End Sub
    How do I keep test2 to remain open when running the macro?

    Thank you!

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Remove this line

    DestWB.Close savechanges:=True
    VBA Noob

  5. #5
    Registered User
    Join Date
    11-11-2007
    Posts
    44
    Quote Originally Posted by VBA Noob
    Remove this line

    DestWB.Close savechanges:=True
    VBA Noob
    Removing this code leaves it open but running the macro again does not save the information. It wants to open the file again and discard any changes made.

    The reason I want the test2.xls to remain open because it is going to sit on a server and the file is fairly large. So running the macro that opens it and closes it will be time consuming. But leaving it open and just keeps adding rows and saving it later will save me a lot of time.

    Thank you again..

    I have a feeling that the code needs to be change somewhere here:
        If bIsBookOpen_RB("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls") Then
            Set DestWB = Workbooks("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls")
        Else
            Set DestWB = Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\Reg60\Macro enabled sheets\test\test2.xls")
        End If

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    This should save changes

    DestWB.Save
    VBA Noob

  7. #7
    Registered User
    Join Date
    11-11-2007
    Posts
    44
    Quote Originally Posted by VBA Noob
    This should save changes

    DestWB.Save
    VBA Noob
    Wow... Thank you very much!

    This is going to save me a lot of time.

+ 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