Consulting

Results 1 to 5 of 5

Thread: dayly data to weekly data

  1. #1
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location

    dayly data to weekly data

    Sub w()
    Dim i As Long, rng As Range
        Columns(1).Insert
        With Range("b2", Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
            .Formula = "=if(and(weekday(b2,2)<weekday(b3,2),b3<>""""),1,"""")"    
            .Value = .Value
            On Error Resume Next
            .SpecialCells(2, 1).EntireRow.Delete               
            On Error GoTo 0
        End With
        Columns(1).Delete
        End Sub
    When run the above macro on Book1.xlsx, data in col AB and CD both change to weekly one. I want data in col CD intact when
    running the macro.
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    If you use entirerow.delete, it also effects data in column C and D

  3. #3
    Instead of entirerow delete, how about this?

    Sub w()    Dim i As Long, rng As Range
        Columns(1).Insert
        With Range("b2", Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
            .Formula = "=if(and(weekday(b2,2)<weekday(b3,2),b3<>""""),1,"""")"
            .Value = .Value
            On Error Resume Next
            .SpecialCells(2, 1).Offset(0, 1).Delete Shift:=xlUp
            .SpecialCells(2, 1).Offset(0, 2).Delete Shift:=xlUp
            On Error GoTo 0
        End With
        Columns(1).Delete
    End Sub

  4. #4
    VBAX Contributor
    Joined
    Apr 2012
    Posts
    107
    Location
    Sloved. Thank you

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    I assume you mean solved ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •