+ Reply to Thread
Results 1 to 4 of 4

Copying cells from one sheet to another if document has been saved.

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329

    Copying cells from one sheet to another if document has been saved.

    Hello.

    I have this problem.

    I have two workbooks. One that collects info from many other workbooks.
    The problem is that I want the first workbook to get information from the other workbooks only if the workbooks has been saved during the current date.

    I have one cell in each of the several workbooks that contains the last date the workbook has been saved. (L1)

    I want something like this to happen:

    "If L1 in workbook 18 is todays date, copy cell A1-G1:A15-G15 to workbook number 2, else do nothing."

    Is this possible to do?

    /Anders

  2. #2
    Mike Fogleman
    Guest

    Re: Copying cells from one sheet to another if document has been saved.

    This line will compare a cell's value to today's date:

    If Range("L1").Value = Date Then

    We need to see your code that loops through the workbooks to help further
    and include any Dimmed variables.

    Mike F
    "a94andwi" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hello.
    >
    > I have this problem.
    >
    > I have two workbooks. One that collects info from many other
    > workbooks.
    > The problem is that I want the first workbook to get information from
    > the other workbooks only if the workbooks has been saved during the
    > current date.
    >
    > I have one cell in each of the several workbooks that contains the last
    > date the workbook has been saved. (L1)
    >
    > I want something like this to happen:
    >
    > "If L1 in workbook 18 is todays date, copy cell A1-G1:A15-G15 to
    > workbook number 2, else do nothing."
    >
    > Is this possible to do?
    >
    > /Anders
    >
    >
    > --
    > a94andwi
    > ------------------------------------------------------------------------
    > a94andwi's Profile:
    > http://www.excelforum.com/member.php...o&userid=21077
    > View this thread: http://www.excelforum.com/showthread...hreadid=384465
    >




  3. #3
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329
    I' m sorry but I do not know how to loop through the worksheet and would really like an example that I can manipulate.

  4. #4
    Forum Contributor
    Join Date
    03-14-2005
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    329
    Hello again.

    Now I have finally found out some way to loop through my files but there are still some major functions I can't understand how to solve.

    Here's the loop:

    Do While FNames <> ""

    'SourceRcount = SourceRange.Rows.Count

    Set myBook = Workbooks.Open(FNames)

    Set SourceRange = myBook.Worksheets(1).Range("A4:L20")

    SourceRcount = SourceRange.Rows.Count

    'Set destrange = basebook.Worksheets(1).Cells(counter, "O")
    Set destrange = basebook.Worksheets(1).Range("A4")

    'Skriv in arbetsbokens namn i kolumn H
    basebook.Worksheets(1).Cells(counter, "M").Value = myBook.Name
    If myBook.Worksheets(1).Range("L1") = Date Then

    'SourceRange.Copy destrange
    ' Instead of this line you can use the code below to copy only the values

    With SourceRange
    'Set destrange = basebook.Worksheets(1).Cells(counter, "O"). _
    Resize(.Rows.Count, .Columns.Count)
    Set destrange = basebook.Worksheets(1).Range("A4"). _
    Resize(.Rows.Count, .Columns.Count)
    End With
    destrange.Value = SourceRange.Value
    End If

    myBook.Close False

    counter = counter + SourceRcount
    FNames = Dir()

    Loop

    The lines written in red above are where I have difficulties.

    On every new worksheet I want only the rows which has some values copied onto the destination worksheet.
    On the destination worksheet I want the first copied values to be copied to Cell A4 and the next values on the cells A5, A6 and so on.
    When the loop continues to the next file and copies the values I want it to continue to copy the values the next empty cell in the destination worksheet.

    Anyone who can help me?

    /anders

+ 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