Array Convert Pasted Range to Dates without looping

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
950
Office Version
  1. 2019
Platform
  1. Windows
I am using this code which works fine:

Code:
Set copyrng = lo_b1.AutoFilter.Range.SpecialCells(xlCellTypeVisible)
copyrng.Copy Destination:=strng
arr = strng.CurrentRegion.Offset(1, 0)
aRws = Evaluate("Row(1:" & UBound(arr) & ")")
arr = Application.Index(arr, aRws, Array(14, 1, 6, 2, 13, 12, 18, 16, 7))

pasterange1.Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr

Set copyrng = Nothing
Erase arr
Erase aRws

The only problem I am having is when I am pasting the array at the end, some of the dates (column2 in the array) appear as text. I have to click on each cell and press enter to be converted to dates. Is there a way to paste as dates from the array?

What also puzzles me is that some entries are correctly shown as dates but most of them are text. I would also avoid looping in the array, as I have hundreds of entries and this will make things unusable.

many thanks!
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try this:

change
Code:
[COLOR=#333333]pasterange1.Resize(UBound(arr, 1), UBound(arr, 2)).Value = arr[/COLOR]

by
Code:
With pasterange1.Resize(UBound(arr, 1), UBound(arr, 2))
    .Value = arr
    .NumberFormat = "dd/mm/yyyy"
    .Value = .Value
End With
 
Upvote 0
this works, but also converts the amount column to dates.. is it possible to restrict this to column(2) of the array please?
 
Upvote 0
Try this

Code:
With pasterange1.Resize(UBound(arr, 1), UBound(arr, 2))
    .Value = arr
    pasterange1.Resize(UBound(arr, 1)).NumberFormat = "General"
    pasterange1.Offset(, 1).Resize(UBound(arr, 1)).NumberFormat = "dd/mm/yyyy"
    .Value = .Value
End With
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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