I am currently making a report based off of Stats in my company. The raw data that I receive has date with a Time Stamp (2 Date Columns - Created/Received). To Remove the time stamp, I set the a custom format to m/d/yyyy and then Delimit each column separately which gives me the correct date. Once I assign my Macro to a button and add new Raw Data I receive this error ----
Does anyone have any tips or understand why I am getting this error even though I am only Delimiting one column at a time?
Sub ComplianceOTRSMacro()
' ComplianceOTRSMacro Macro
' Format Date - Refresh Pivot Tables
Columns("D:E").Select
Selection.NumberFormat = "m/d/yyyy"
Columns("D:D").Select
Selection.TextToColumns Destination:=Range("OTRSData[[#Headers],[Created]]") _
, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
Columns("E:E").Select
Selection.TextToColumns Destination:=Range( _
"OTRSData[[#Headers],[Close Time]]"), DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:= _
False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1) _
, TrailingMinusNumbers:=True
Range("OTRSData[[#Headers],[Ticket'#]]").Select
Sheets("Dashboard").Select
ActiveWorkbook.RefreshAll
End Sub
Related
I have recorded a macro that will convert a column of dates in UK format to text by using Text to Columns when recording it, but the text it returns is in US format. Text to Columns does the job when its outside of a macro so not sure why it wouldn't work when used in a macro.
Is there a way to have the text in UK format and not have it converted to US format? I believe the below is the relevant part:
Selection.TextToColumns Destination:=Range("E1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True
Columns("F:F").Select
Selection.TextToColumns Destination:=Range("F1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True
Columns("A:P").Select
Selection.Copy
Windows("Xero Upload Template V2.xlsx").Activate
Range("A4").Select
ActiveSheet.Paste```
If I understand correctly then your data is in column 5 and 6 which you need to convert. Please try below code.
Dim c As Long
For c = 5 To 6
Columns(c).TextToColumns DataType:=xlDelimited, Tab:=False, Semicolon:=False,
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 5)
Columns(c).NumberFormat = "dd-mm-yyyy"
Next c
I want to change format from Date to Number and It doesnt changes. I have to click two times on every cell to change it.
I found a solution that text to column works here. Unfortunatelly the recorded code doesn't work.
Worksheets("Data for LN").Range("i2:i" & datarange).Select
Selection.NumberFormat = "0.00"
Selection.TextToColumns Destination:=Range("I2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Any ideas how to change it?
I'm trying to write a code to do the following:
Using text-to-columns,the data should get divided in different columns.
The data in Cells A1-A8 is like this:
This data should appear in different columns.
Like this?
Sub Macro()
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=":", FieldInfo:=Array(Array(1, 1), Array(2, 1)),
End Sub
You can build the FieldInfo parameter dynamically by building out the string. In the example below, there are 10 resultant columns. The For loop builds the sFieldInfo variable, and specifies all the columns in Text format.
sComma = ""
sFieldInfo = ""
For x = 1 To 10
sFieldInfo = sFieldInfo & sComma & " Array(" & x & ", xlTextFormat)"
sComma = ","
Next x
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("J5"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar:="/", _
TrailingMinusNumbers:=True, _
FieldInfo:=Array(sFieldInfo)
I am facing issue after copy and paste from export file from SAP it ask to convert to number option which is like error without converting to number formulas do not work. also cell value is number only.
I tried to make macro but it works on single column only. how to make it work on multiple column together and make it faster also as it stuck exel for long time.
code for converting to number
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Columns("F:F").Select
Selection.TextToColumns Destination:=Range("F1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Columns("G:G").Select
Selection.TextToColumns Destination:=Range("G1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
How shorter code and combine for multiple columns in single line.
Use an xlFixedWidth in your Range.TextToColumns method.
Dim c As Long, vCOLs As Variant
vCOLs = Array(1, 6, 7) 'columns A, F and G
With Worksheets("Sheet1")
For c = LBound(vCOLs) To UBound(vCOLs)
With .Column(c)
.TextToColumns Destination:=.Cells(1), DataType:=xlFixedWidth, _
FieldInfo:=Array(0, 1), TrailingMinusNumbers:=True
End With
Next c
End With
The variant array allow you to quickly specify the columns to be processed. Even with a large (~250K) number of rows, this should be fairly quick to cycle through.
I have tried creating a macro that automatically formats a column value to change date and time just to date, however when the macro is run the cell values dont automatically update.
I currently need to make the following function selection happen using VBA for excel 2010.
Data/Text to Columns/Next button (keep default "Delimited")/Next button (keep default "tab")/Next button (keep default "General"/Finish button
I have tried recording functions but the VBA doesn't work. HELPPPPPPPPPPPPPPPPPPPPP!!!!!
Here is my code so far.
' Autochange_Extractdata_Date_Format Macro
'
Sheets("Data Extract").Select
Columns("AK:AK").Select
Selection.NumberFormat = "m/d/yyyy"
Columns("AK:AK").Select
Selection.TextToColumns Destination:=Range("AK1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
End Sub
From the symptoms you described it sounds like your field is initially in TEXT format, that's why changing it to number format doesn't do anything. When you click into the cell it automatically converts it to a number.
Try this
Columns("AK:AK").NumberFormat = "m/d/yyyy"
Columns("AK:AK").Value = Columns("AK:AK").Value '//This will convert each properly
Columns("AK:AK").Select
Selection.TextToColumns Destination:=Range("AK1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Because i couldnt work out how to update the cell value i managed to work this code to change the cell value instead from Date time just to Date.
works a treat!!!
' Autochange_Extractdata_Date_Format Macro
Sheets("Data Extract").Select
Columns("AK:AK").Select
Selection.NumberFormat = "m/d/yyyy"
Range("AK4:AK999999").Select
Dim c As Range
For Each c In Selection
Dim v As String
v = c.value
If c.value <> Empty Then
c.value = DateValue(c.value)
Else
Exit For
End If
Next
Range("A1").Select
End Sub