Consulting

Results 1 to 5 of 5

Thread: Code to be used for all the ranges in the column

  1. #1
    VBAX Regular
    Joined
    Jul 2015
    Posts
    32
    Location

    Code to be used for all the ranges in the column

    I have used the below code to generate the dates within the date range (H3:I3)

    Sub GenerateDates1()
    Dim FirstDate As Date
    Dim LastDate As Date
    Dim NextDate As Date
    
    FirstDate = Range("H3").Value
    LastDate = Range("I3").Value
    
    NextDate = FirstDate
    Range("H4").Select
    
    Do Until NextDate >= LastDate
    NextDate = DateAdd("d", NextDate, 1)
        ActiveCell.Value = NextDate
        ActiveCell.Offset(1, 0).Select
     
    Loop
    End Sub

    Can someone help me. I need to check all the date range in the column H and I.

    Very Urgent… very grateful if someone can provide me the coding.

    -Tharabai
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try this macro while your sheet3 is the active sheet:
    Sub blah()
    For Each cll In Columns("I:I").SpecialCells(xlCellTypeConstants, 1).Cells
      If IsDate(cll.Value) And IsDate(cll.Offset(, -1).Value) Then
        'cll.Select
        x = cll.Value - cll.Offset(, -1).Value
        If x >= 1 Then
          cll.Offset(1).Resize(x).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
          cll.Offset(, -1).AutoFill Destination:=cll.Offset(, -1).Resize(x + 1), Type:=xlFillDefault
        End If
      End If
    Next cll
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular
    Joined
    Jul 2015
    Posts
    32
    Location
    Awesome !! works like a magic...

    Thank you so much for your timely help

    one more addition to the above, I want to fill the column A (ID) values also. The ID should be same as previous cell value.

    -Tharabai

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Sub blah2()
        For Each cll In Columns("I:I").SpecialCells(xlCellTypeConstants, 1).Cells
            If IsDate(cll.Value) And IsDate(cll.Offset(, -1).Value) Then
                x = cll.Value - cll.Offset(, -1).Value
                If x >= 1 Then
                    cll.Offset(1).Resize(x).EntireRow.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                    cll.Offset(, -1).AutoFill Destination:=cll.Offset(, -1).Resize(x + 1), Type:=xlFillDefault
                     cll.Offset(, -8).Copy Destination:=cll.Offset(1, -8).Resize(x)
                End If
            End If
        Next cll
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    VBAX Regular
    Joined
    Jul 2015
    Posts
    32
    Location
    Thank you so much.. It really helped me

Posting Permissions

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