Keep source formatting.

Harshil Mehta

Board Regular
Joined
May 14, 2020
Messages
64
Office Version
  1. 2013
Platform
  1. Windows
The below code works completely fine. I just want the code to retain the source formatting. For example: my source data also contains numbers which are stored as text, however the below code coverts them into numbers in the output. I don't want the code to convert them instead retain the source formatting.

Could anyone please help me solve this?

VBA Code:
Sub test_1()
       Dim Ary As Variant, Nary As Variant
       Dim r As Long, c As Long, nr As Long
       
       With Sheet7
          c = .Cells.Find("*", , , , xlByColumns, xlPrevious, , , False).Column
          Ary = .Range("A11", .Range("A" & Rows.Count).End(xlUp)).Resize(, c).Value2
       End With
       ReDim Nary(1 To UBound(Ary), 1 To c - 1)
       For r = 1 To UBound(Ary)
          If LCase(Ary(r, 1)) = "fine" Then
             nr = nr + 1
             For c = 2 To UBound(Ary, 2)
                Nary(nr, c - 1) = Ary(r, c)
             Next c
          End If
       Next r
       Sheet3.Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(nr, UBound(Nary, 2)).Value = Nary
    End Sub
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,400
Try this...
VBA Code:
    With Sheet3.Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(nr, UBound(Nary, 2))
        .NumberFormat = "@"    'Text format
        .Value = Nary
    End With
 
Solution

Harshil Mehta

Board Regular
Joined
May 14, 2020
Messages
64
Office Version
  1. 2013
Platform
  1. Windows
Try this...
VBA Code:
    With Sheet3.Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(nr, UBound(Nary, 2))
        .NumberFormat = "@"    'Text format
        .Value = Nary
    End With
Works super fine. Thanks for the quick response.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,420
Messages
5,624,683
Members
416,040
Latest member
patriciocabello

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top