+ Reply to Thread
Results 1 to 5 of 5

Copy Data by Date (Traspose data)

Hybrid View

  1. #1
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Copy Data by Date (Traspose data)

    Hi.

    I have two sheets (DataBase) and (summary), i need copy by date and paste in summary.

    the problem i need date arranged in a somewhat different.

    look my file
    Attached Files Attached Files
    Last edited by marreco; 06-11-2014 at 11:51 AM.
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  2. #2
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Copy Data by Date (Traspose data)

    Hi

    Someone can help me?

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Copy Data by Date (Traspose data)

    Hi, marreco,

    the basic function for what you asked could be supplied by applying a Pivot Table.

    Sub EF1017281()
    Dim wsDat     As Worksheet
    Dim wsSum     As Worksheet
    Dim lngRC     As Long
    Dim lngArr    As Long
    Dim var       As Variant
    Dim varSplit  As Variant
    
    Set wsDat = Sheets("DataBase")
    Set wsSum = Sheets("Summary")
    
    'get relevant data according to Month
    With wsDat
      ReDim var(1 To .Range("A" & Rows.Count).End(xlUp).Row, 1 To 2)
      For lngRC = 2 To .Range("A" & Rows.Count).End(xlUp).Row
        If Month(.Cells(lngRC, "A").Value) = Month(wsSum.Range("B1").Value) Then
          For lngArr = LBound(var) To UBound(var)
            If var(lngArr, 1) = .Cells(lngRC, 2) & "|" & .Cells(lngRC, 3) Or Len(var(lngArr, 1)) = 0 Then
              Exit For
            End If
          Next lngArr
          If lngArr < UBound(var) Then
            var(lngArr, 1) = .Cells(lngRC, 2) & "|" & .Cells(lngRC, 3)
            var(lngArr, 2) = var(lngArr, 2) & .Cells(lngRC, 1) & "|"
          End If
        End If
      Next lngRC
    End With
    
    'clear summary, write and sort data
    With wsSum
      .Range("A3").CurrentRegion.ClearContents
      For lngArr = LBound(var) To UBound(var)
        If var(lngArr, 1) = "" Then Exit For
        Cells(lngArr + 2, "A").Value = Split(var(lngArr, 1), "|")(0)
        Cells(lngArr + 2, "B").Value = Split(var(lngArr, 1), "|")(1)
        varSplit = Split(var(lngArr, 2), "|")
        For lngRC = LBound(varSplit) To UBound(varSplit) - 1
          Cells(lngArr + 2, 3 + lngRC).Value = varSplit(lngRC)
        Next lngRC
      Next lngArr
      .Range("A3").CurrentRegion.Sort _
          Key1:=.Range("A3"), Order1:=xlAscending, _
          Key2:=.Range("B3"), Order2:=xlAscending, _
          Header:=xlNo, _
          OrderCustom:=1, _
          MatchCase:=False, _
          Orientation:=xlTopToBottom
    End With
    
    Set wsSum = Nothing
    Set wsDat = Nothing
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Copy Data by Date (Traspose data)

    With an pivot table.

    See the attached file.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  5. #5
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Copy Data by Date (Traspose data)

    Hi HaHoBe, your code is very good.

    I'm impressed with your solution.

    I will try to understand the code (in the loop), to learn how it was done.
    thank you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy data from one sheet to another if the date is equal or higher than a gien date
    By ANDREAAS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2013, 02:57 PM
  2. Replies: 27
    Last Post: 08-17-2011, 05:25 PM
  3. Copy Data, Find Date, Paste data below Date
    By dgibson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2011, 09:31 PM
  4. Copy rows of data if date in cells meets certain date criteria
    By angrycartoon12 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-02-2010, 05:57 AM
  5. copy date based on date -refer to date range
    By mindpeace in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2006, 08:35 AM

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