Results 1 to 23 of 23

VB Code to reorganize data

Threaded View

  1. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: VB Code to reorganize data

    hELLO rIZ,

    Okay, this macro will check the contents of cell K1. If the cell does not contain a Date, it will exit silently. If the Date cannot be found, a message will be displayed.

    Sub ReOrganizeByDay()
    
        Dim Col     As Variant
        Dim Data    As Variant
        Dim DstRng  As Range
        Dim DTRng   As Range
        Dim Row     As Long
        Dim SrcRng  As Range
        Dim Wks     As Worksheet
        
            Set Wks = ThisWorkbook.Worksheets("Sheet1")
            
            Set DTRng = Wks.Range("K1")
            If IsEmpty(DTRng) Then Exit Sub
            
            Set SrcRng = Wks.Cells.Find(DTRng.Value, DTRng, xlFormulas, xlWhole, xlByRows, xlNext, False, False, False)
            If SrcRng.Address = DTRng.Address Then
                MsgBox "The Clock-In/Out date and time """ & DTRng.Text & """ was Not Found.", vbExclamation
                Exit Sub
            End If
            
            Set SrcRng = SrcRng.CurrentRegion
            
            Set DstRng = Wks.Range("A3")
                    
                ReDim Data(SrcRng.Rows.Count, 3)
                
                For Col = 1 To 3
                
                    For Row = 2 To SrcRng.Rows.Count
                        Set Cell = SrcRng.Cells(Row, 1)
                        Data(Row - 2, 0) = SrcRng.Cells(1, 1)
                        Data(Row - 2, 1) = Cell.Value
                        Data(Row - 2, 2) = Cell.Offset(0, 1).Value
                        Data(Row - 2, 3) = Cell.Offset(0, 2).Value
                    Next Row
                    
                    DstRng.Resize(SrcRng.Rows.Count - 1, 4).Value = Data
                Next Col
            
    End Sub
    Last edited by Leith Ross; 03-28-2016 at 09:34 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. reorganize raw data..
    By BPHAN2 in forum Excel General
    Replies: 1
    Last Post: 07-23-2014, 05:20 PM
  2. I need to reorganize the data with VBA
    By baetienne in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-29-2014, 03:40 PM
  3. Reorganize data
    By Kayline in forum Excel General
    Replies: 6
    Last Post: 03-06-2013, 11:57 AM
  4. Reorganize data
    By ngpm515 in forum Excel General
    Replies: 0
    Last Post: 11-02-2011, 05:19 PM
  5. Reorganize a data set
    By RPADC in forum Excel General
    Replies: 3
    Last Post: 07-11-2010, 02:19 PM
  6. Reorganize data
    By pentiumeric in forum Excel General
    Replies: 13
    Last Post: 07-13-2009, 04:32 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