Printed values do not follow formatting

Viewed 31

I have a simple VBA code that reads a range of values from one excel file and transcribes them into a second excel file. The main problem is that the values I write into this second file do not follow the established formatting that this file already has, which gives me some issues later down the line.

Can anyone give me some pointers to maintain the formatting of the cells I am writing into?

Thanks

READING

' Reading loop variables
Dim i, count, n_rows As Integer
Dim Inputs() as Variant

count = 0
ReDim Inputs(1 To n_rows, 1 To 2)


' Reading loop
For i = row_init To row_fin
    
    If Trim(ActiveSheet.Cells(i, 1)) <> "" Then
        
        count = count + 1
        
        ' Read the row key
        Inputs(count, 1) = Trim(ActiveSheet.Cells(i, 1))
        
        ' Read the given answer
        Inputs(count, 2) = Trim(ActiveSheet.Cells(i, 3))
        
    End If
    
Next i

PRINTING

Dim target, business_line as String
Dim row_start, row_end as Integer
Dim RowKeyEquivalence, BusinessEquivalence as Range

' Printing loop
For i = 1 To n_rows
    
    With Application.WorksheetFunction
        ' Find line target to print in Decisions sheet from the Row Key
        target = .VLookup(Inputs(i, 1), RowKeyEquivalence, 2, False)
        ' Find Business Line corresponding to Row Key
        business_line = .VLookup(Inputs(i, 1), RowKeyEquivalence, 3, False)
        
        ' Store initial and final rows for a Business Line
        row_start = .VLookup(business_line, BusinessEquivalence, 2, False)
        row_end = .VLookup(business_line, BusinessEquivalence, 3, False)
        
    End With
    
    ' Run through Decisions sheet range and print the response
    For Each cell In Decisions_Row
    
        If Trim(target) = Trim(cell.Value) And cell.Row >= row_start And cell.Row <= row_end Then
            
            '****************************************************
            ' This is where I print
            '****************************************************
            ActiveSheet.Cells(cell.Row, print_col) = Inputs(i, 2)
            
            current_row = cell.Row
            GoTo NextValue
        
        Else
            GoTo NextCell
        
        End If
        
NextCell:
    Next cell
    
NextValue:
Next i
0 Answers
Related