Keep source formatting.

Harshil Mehta

Board Regular
Joined
May 14, 2020
Messages
85
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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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
Back
Top