Results 1 to 3 of 3

Problem with Macro that sorts random date ranges into daily data

Threaded View

cs454 Problem with Macro that sorts... 01-21-2014, 11:08 AM
AB33 Re: Problem with Macro that... 01-21-2014, 11:36 AM
cs454 Re: Problem with Macro that... 01-21-2014, 12:00 PM
  1. #1
    Registered User
    Join Date
    01-20-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    52

    Problem with Macro that sorts random date ranges into daily data

    Hi all,

    I have attached my excel file with a macro that splits everything into daily data. The first sheet is my original data and the second is after I have run a macro.

    This works fine until you go to row 148 on the second sheet. The Retailer Descriptions: Ttd Toffee and Ttd Van has started on the correct date, but then only appears every other two days, instead of everyday in the range provided. I have applied this to a large dataset and noticed the same problem always.

    Any help would be greatly appreciated!

    My VBA code:

    Option Explicit

    Sub ReformatData()
    Dim LR As Long, Rw As Long, Dif As Long
    Application.ScreenUpdating = False
    'Setup
    Sheets("Sheet1").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = "Daily"
    LR = Range("A" & Rows.Count).End(xlUp).Row

    For Rw = LR To 2 Step -1
    Dif = Range("B" & Rw) - Range("A" & Rw)
    If Dif > 0 Then
    Rows(Rw + 1).Resize(Dif).Insert xlShiftDown
    With Range("A" & Rw + 1).Resize(Dif)
    .FormulaR1C1 = "=R[-1]C + 1"
    .NumberFormat = "YYYY/MM/DD"
    End With
    End If
    Next Rw

    Columns("B:B").Delete xlShiftToLeft

    LR = Range("A" & Rows.Count).End(xlUp).Row
    With Range("B1:C" & LR)
    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"
    .Value = .Value
    End With

    Range("A1").CurrentRegion.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess

    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to sum daily durations from date ranges
    By MechEngSk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2013, 02:11 AM
  2. [SOLVED] Macro that automatically sorts by date without pressing a shortcut
    By bellfellas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2013, 01:24 PM
  3. Replies: 0
    Last Post: 12-18-2012, 05:40 AM
  4. Unique random numbers daily calculation macro
    By pco101 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-14-2011, 04:43 AM
  5. [SOLVED] Sorts on variable ranges
    By bman342 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-28-2006, 03:47 PM

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