vba_rearrange_data
Posted: Mon Dec 02, 2024 9:30 am
Hi Dear!
I need your hand to correct data arranging in a new sheet.I try but it's no luck
Please help fix it to get outputs like the hightlighted sheet.
Noted:you can change variable to whatever it is easier to read as well.
thank you in advance
I need your hand to correct data arranging in a new sheet.I try but it's no luck
Code: Select all
Sub FormatLoanData()
Dim ws As Worksheet
Dim outputWs As Worksheet
Dim lastRow As Long
Dim currentRow As Long
Dim outputRow As Long
Dim currentOfficer As String
' Set the worksheets
Set ws = ThisWorkbook.Sheets("RawData") ' Change to your actual data sheet name
Set outputWs = ThisWorkbook.Sheets.Add
outputWs.Name = "Output"
outputRow = 2 ' Start output from the second row
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row ' Get last row with data
For currentRow = 2 To lastRow ' Assuming first row is header
' Check for Credit Officer header
If InStr(ws.Cells(currentRow, 1), "Credit Officer:") > 0 Then
currentOfficer = ws.Cells(currentRow, 1).Value ' Store current officer
' Skipping the credit officer line
ElseIf ws.Cells(currentRow, 1).Value <> "" Then
' Copy Data to formatted worksheet
outputWs.Cells(outputRow, 1).Value = ws.Cells(currentRow, 1).Value
outputWs.Cells(outputRow, 2).Value = ws.Cells(currentRow, 2).Value
outputWs.Cells(outputRow, 3).Value = ws.Cells(currentRow, 3).Value
outputWs.Cells(outputRow, 4).Value = ws.Cells(currentRow, 4).Value
outputRow = outputRow + 1 ' Increment output row counter
End If
Next currentRow
End Sub
Noted:you can change variable to whatever it is easier to read as well.
thank you in advance