Consulting

Results 1 to 6 of 6

Thread: Need Macro to create a Format

  1. #1

    Smile Need Macro to create a Format

    Hello Guys,

    Need a small help in creating a macro which will segregate the data in a summarized format. Please refer the attach excel file for clear picture. Many thanks for the help.

    Please Note: List can vary in numbers.


    Many Thanks,
    Manoj Kumar
    Attached Files Attached Files
    Regards,
    Manoj

    "There are no failures - just experiences and your reactions to them."

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]Sub ProcessData()
    Dim testValue As Long
    Dim bandText As String
    Dim lastrow As Long
    Dim i As Long

    With ActiveSheet

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Columns("A").Insert
    testValue = 45
    bandText = "45+"
    For i = lastrow - 1 To 1 Step -1

    If Not .Cells(i, "C").Value >= testValue Then

    .Cells(i + 1, "A").Resize(, 3).Insert Shift:=xlDown
    .Cells(i + 1, "A").Value = bandText
    .Cells(i + 1, "A").Resize(, 3).Interior.ColorIndex = 15
    If testValue = 45 Then

    testValue = 40
    bandText = "40"
    Else

    testValue = 30
    bandText = "30-35"
    End If
    End If
    Next i

    .Columns("C").Copy
    .Columns("A").PasteSpecial Paste:=xlPasteFormats
    End With

    Application.CutCopyMode = False
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thank you! xld....it's just perfect.. Thanks again
    Regards,
    Manoj

    "There are no failures - just experiences and your reactions to them."

  4. #4
    Just one more thing; it;s not categorizing the lowest category, i.e. not giving the header "30-35"...

    Thanks,
    Regards,
    Manoj

    "There are no failures - just experiences and your reactions to them."

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This should fix it

    [VBA]Sub ProcessData()
    Dim testValue As Long
    Dim bandText As String
    Dim lastrow As Long
    Dim i As Long

    With ActiveSheet

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Columns("A").Insert
    testValue = 45
    bandText = "45+"
    For i = lastrow - 1 To 1 Step -1

    If Not .Cells(i, "C").Value >= testValue Or i = 1 Then

    .Cells(i + 1, "A").Resize(, 3).Insert Shift:=xlDown
    .Cells(i + 1, "A").Value = bandText
    .Cells(i + 1, "A").Resize(, 3).Interior.ColorIndex = 15
    If testValue = 45 Then

    testValue = 40
    bandText = "40"
    Else

    testValue = 30
    bandText = "30-35"
    End If
    End If
    Next i

    .Columns("C").Copy
    .Columns("A").PasteSpecial Paste:=xlPasteFormats
    End With

    Application.CutCopyMode = False
    End Sub
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Thanks a lot; xld.. it working now...
    Regards,
    Manoj

    "There are no failures - just experiences and your reactions to them."

Posting Permissions

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