Consulting

Results 1 to 5 of 5

Thread: Need Help converting columns to YML format

  1. #1

    Need Help converting columns to YML format

    Hello All,

    Looking for some help on how to achieve the following. I have two sheets. In Sheet1 i have three columns (Variable, Value, Server) with various forms of data. I'm looking to transfer that data into a specific format on sheet2. It would be setup in YML format with the variable name as the main category. Then each server would be listed out with the value listed after it. Does anyone have any ideas on how i can achieve this. Your help is appreciated. VBA Example.xlsx

  2. #2
    Try this code
    Sub Test()    
        Dim txt As String, f As Integer, iRow As Long, iCol As Long
        With Sheet1
            For iRow = 1 To WorksheetFunction.CountA(.Range("A:A"))
                For iCol = 1 To WorksheetFunction.CountA(.Range("1:1"))
                    txt = txt & .Cells(1, iCol) & ": " & .Cells(iRow, iCol) & vbCrLf
                Next iCol
            Next iRow
        End With
        f = FreeFile
        Open ThisWorkbook.Path & "\Output.yml" For Output As #f
        Print #f, txt
        Close #f
    End Sub

  3. #3
    Thanks for the reply. It's working just need the outcome changed a little. The Headers of Variable Name, Value & Server should not show up on the output. And after the variable name there should be ":" and after the server name before the value there should be a ":".. Sheet 2 give an example on the ouput look.
    Last edited by trevor2524; 02-06-2023 at 03:24 PM.

  4. #4
    Try this version
    Sub Test()
        Dim txt As String, prevVar As String, f As Integer, iRow As Long
        With Sheet1
            prevVar = .Cells(2, 1)
            txt = .Cells(2, 1) & ":" & vbCrLf & "  " & .Cells(2, 3) & ": " & .Cells(2, 2) & vbCrLf
            For iRow = 3 To WorksheetFunction.CountA(.Range("A:A"))
                If prevVar <> .Cells(iRow, 1) Then
                    prevVar = .Cells(iRow, 1)
                    txt = txt & vbCrLf & prevVar & ":" & vbCrLf & "  " & .Cells(iRow, 3) & ": " & .Cells(iRow, 2) & vbCrLf
                Else
                    txt = txt & Space(2) & .Cells(iRow, 3) & ": " & .Cells(iRow, 2) & vbCrLf
                End If
            Next iRow
        End With
        f = FreeFile
        Open ThisWorkbook.Path & "\Output.yml" For Output As #f
        Print #f, txt
        Close #f
    End Sub

  5. #5
    another example.
    Attached Files Attached Files

Posting Permissions

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