Text to Columns VBA Optimizing

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
893
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have the below code that changes the range of cells. The cell contains a date in general format YYYYMMDD. And needs to end up in date format with MM/DD/YYYY. Is there a cleaner quicker way to do the below? I am just trying to reduce the line of code in my existing sub. Thanks in advance

VBA Code:
'Start Date
wsDSTN.Range("K2").Resize(rws).TextToColumns Destination:=Range("K2"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 5), TrailingMinusNumbers:=True

'End Date
wsDSTN.Range("L2").Resize(rws).TextToColumns Destination:=Range("L2"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 5), TrailingMinusNumbers:=True

'Due Date
wsDSTN.Range("M2").Resize(rws).TextToColumns Destination:=Range("M2"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 5), TrailingMinusNumbers:=True
wsDSTN.Range("K2:M2").Resize(rws).NumberFormat = "mm/dd/yyyy"
 
Maybe...

VBA Code:
Dim i As Integer

For i = 11 To 13

wsDSTN.Cells(2, i).Resize(rws).TextToColumns Destination:=wsDSTN.Cells(2, i), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 5), TrailingMinusNumbers:=True

Next i

wsDSTN.Range("K2:M2").Resize(rws).NumberFormat = "mm/dd/yyyy"
 
Upvote 0
Solution

Forum statistics

Threads
1,226,836
Messages
6,193,247
Members
453,783
Latest member
Chandni

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