• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need help in Formula

Please go through the attached file , i created my query inside.Anyone helps me to solve this issue.
 

Attachments

  • batch.xlsx
    20.3 KB · Views: 9
Code:
Sub BatchMaker()

Dim FstVal, LstVal As String
Dim FstRow, LstRow As Integer

Range("A2").Select

Do Until IsEmpty(ActiveCell)

    'End Batch
    Do Until IsEmpty(ActiveCell)
        If ActiveCell.Offset(1, 0).Value = ActiveCell.Value + 1 Then
            ActiveCell.Offset(1, 0).Select
        Else
            Exit Do
        End If
    Loop
    LstVal = ActiveCell.Value
    LstRow = ActiveCell.Row
   
    'Start Batch
    Do Until IsEmpty(ActiveCell)
        If ActiveCell.Offset(-1, 0).Value = ActiveCell.Value - 1 Then
            ActiveCell.Offset(-1, 0).Select
        Else
            Exit Do
        End If
    Loop
    FstVal = ActiveCell.Value
    FstRow = ActiveCell.Row
   
    'Write batch
    If FstRow = LstRow Then
        Range("B" & FstRow).Value = FstVal
    Else
        Range("B" & FstRow).Value = FstVal & "-" & LstVal
    End If
        Range("A" & LstRow + 1).Select
   
Loop

MsgBox "Macro completed", vbInformation, ""

End Sub
 
Back
Top