Vba: copy and past numbers stored as text

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I have a huge amount of records in which a lot of number are stored as text.

In order to simplify, I have created the above image:

https://imgur.com/a/H5IXsEm


The task is the following: for each value in colomn E, put in column F the related value as reported in column B, keeping the format "Number stored as text", if any.

I have tried with a Application.VLookup approach, but it doesn't allow to keep the format.

How can I figure this out? (probably with a copy and paste approach)

In the example I would like:
in F2 3924994 (see B5)
in F3 3473434 (see B12)
in F4 0117509 (see B15) stored as text because in B15 it is stored as text.

Thank's.
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
try adding this
Code:
.NumberFormat = "@"
'so something like
Stuff = Application.WorksheetFunction.Vlookup(blah blah blah)
Stuff.NumberFormat = "@"
 
Upvote 0
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub VLookupTextNumbers()
  Dim R As Long, Table As Range, Data As Variant, Result As Variant
  Set Table = Range("A2", Cells(Rows.Count, "B").End(xlUp))
  Data = Range("E2", Cells(Rows.Count, "E").End(xlUp))
  ReDim Result(1 To UBound(Data), 1 To 1)
  For R = 1 To UBound(Data)
    Result(R, 1) = CStr(Application.VLookup(Data(R, 1), Table, 2, False))
  Next
  With Range("F2").Resize(UBound(Result))
    .NumberFormat = "@"
    .Value = Result
  End With
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Well, it works perfectly.

Thank's.



Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub VLookupTextNumbers()
  Dim R As Long, Table As Range, Data As Variant, Result As Variant
  Set Table = Range("A2", Cells(Rows.Count, "B").End(xlUp))
  Data = Range("E2", Cells(Rows.Count, "E").End(xlUp))
  ReDim Result(1 To UBound(Data), 1 To 1)
  For R = 1 To UBound(Data)
    Result(R, 1) = CStr(Application.VLookup(Data(R, 1), Table, 2, False))
  Next
  With Range("F2").Resize(UBound(Result))
    .NumberFormat = "@"
    .Value = Result
  End With
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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