Consulting

Results 1 to 3 of 3

Thread: Trim rows in multiple sheets

  1. #1

    Trim rows in multiple sheets

    Hi Friends

    Can someone please help me with a VBA code. I have three to four tabs each containing approx 20-35 rows of this data


    { "user" : "DC=Certificate Manager,O=Test Inc.,OU=QA:dc.group.1339956,CN=vid,UID=identity:dc.group.1359009", "roles" : [ { "role" : "QA", "db" : "admin" }, { "role" : "Test", "db" : "admin" }, { "role" : "ADMIN", "db" : "admin" } ] }


    Can somebody help me out with a vba code to trim the above line to this


    { "user" : "DC=Certificate Manager,O=Test Inc.,OU=QA:dc.group.1339956,CN=vid,UID=identity:dc.group.1359009" }

    Currently I am manually doing this, I am searching ", "roles" : " and manually replacing with " }%", then doing a text to column, applying delimiter as % . I tried recording a macro and my excel crashed I will really appreciate if someone can help me.

    Thanks,

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Try this


    Option Explicit
    
    
    Sub test()
        Dim ws As Worksheet
        Dim r As Range, c As Range
        Dim n As Long
        
        Application.ScreenUpdating = False
        
        For Each ws In ActiveWorkbook.Worksheets
            Set r = Nothing
            On Error Resume Next
            Set r = ws.UsedRange.SpecialCells(xlCellTypeConstants, xlTextValues)
            On Error GoTo 0
            
            If Not r Is Nothing Then
                For Each c In r.Cells
                    n = InStr(c.Value, ", ""roles""")
                    If n > 0 Then c.Value = Left(c.Value, n - 1) & "}"
                Next
            End If
        Next
    
    
        Application.ScreenUpdating = False
    
    
        MsgBox "Done"
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3

    [SOLVED] Thank you !

    Quote Originally Posted by Paul_Hossler View Post
    Try this


    Option Explicit
    
    
    Sub test()
        Dim ws As Worksheet
        Dim r As Range, c As Range
        Dim n As Long
        
        Application.ScreenUpdating = False
        
        For Each ws In ActiveWorkbook.Worksheets
            Set r = Nothing
            On Error Resume Next
            Set r = ws.UsedRange.SpecialCells(xlCellTypeConstants, xlTextValues)
            On Error GoTo 0
            
            If Not r Is Nothing Then
                For Each c In r.Cells
                    n = InStr(c.Value, ", ""roles""")
                    If n > 0 Then c.Value = Left(c.Value, n - 1) & "}"
                Next
            End If
        Next
    
    
        Application.ScreenUpdating = False
    
    
        MsgBox "Done"
    End Sub

    Thank you so much

Posting Permissions

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