Excel文本到列更改date格式
我遇到了Excel VBA和Text-to_Columns的问题。
我有30多个文本文件,其中一些包含格式为DD / MM / YYYY的date。 我正在使用VBAmacros导入它们,删除不需要的数据,然后将文件重新组合为CSV格式。 最小的文件包含大约600行和20列,最大的文件包含1,000,000行和93列(800MB +文件)。
当我使用VBA文本将其提取到列代码时,date格式从DD / MM / YYYY更改为MM / DD / YYYY。 (例如2015年11月5日 – 2015年11月5日,2015年5月11日11月5日)。 date通常不在同一列中,并且在每个文件中都不会有相同的名称。
这是使用的VBA代码:
Sub Stripper() ' Go through each spreadsheet, and extract from Text-to-column ' System allows for 150 columns ' Text-to-column can handle commas, semicolons, and pipe delimitations Application.ScreenUpdating = False Application.DisplayAlerts = False Application.DisplayStatusBar = False Dim y As Variant Dim lastColumn As Integer Dim k As Integer Dim MT As Integer Dim Cd As Integer k = Sheets.Count y = 1 MT = 0 Cd = 0 While y <= k t = Sheets(y).Name If t = "Launch" Then ElseIf Left(t, 4) = "MFGI" Or IsNumeric(Left(t, 1)) = True Then Worksheets(t).Activate Columns("A:A").Select Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _ Semicolon:=True, Comma:=False, Space:=False, Other:=True, OtherChar _ :="|", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), _ Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), _ Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), _ Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), _ Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1), Array(35, 1), Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), _ Array(41, 1), Array(42, 1), Array(43, 1), Array(44, 1), Array(45, 1), Array(46, 1), Array(47, 1), Array(48, 1), Array(49, 1), Array(50, 1), _ Array(51, 1), Array(52, 1), Array(53, 1), Array(54, 1), Array(55, 1), Array(56, 1), Array(57, 1), Array(58, 1), Array(59, 1), Array(60, 1), _ Array(61, 1), Array(62, 1), Array(63, 1), Array(64, 1), Array(65, 1), Array(66, 1), Array(67, 1), Array(68, 1), Array(69, 1), Array(70, 1), _ Array(71, 1), Array(72, 1), Array(73, 1), Array(74, 1), Array(75, 1), Array(76, 1), Array(77, 1), Array(78, 1), Array(79, 1), Array(80, 1), _ Array(81, 1), Array(82, 1), Array(83, 1), Array(84, 1), Array(85, 1), Array(86, 1), Array(87, 1), Array(88, 1), Array(89, 1), Array(90, 1), _ Array(91, 1), Array(92, 1), Array(93, 1), Array(94, 1), Array(95, 1), Array(96, 1), Array(97, 1), Array(98, 1), Array(99, 1), Array(100, 1), _ Array(101, 1), Array(102, 1), Array(103, 1), Array(104, 1), Array(105, 1), Array(106, 1), Array(107, 1), Array(108, 1), Array(109, 1), Array(110, 1), _ Array(111, 1), Array(112, 1), Array(113, 1), Array(114, 1), Array(115, 1), Array(116, 1), Array(117, 1), Array(118, 1), Array(119, 1), Array(120, 1), _ Array(121, 1), Array(122, 1), Array(123, 1), Array(124, 1), Array(125, 1), Array(126, 1), Array(127, 1), Array(128, 1), Array(129, 1), Array(130, 1), _ Array(131, 1), Array(132, 1), Array(133, 1), Array(134, 1), Array(135, 1), Array(136, 1), Array(137, 1), Array(138, 1), Array(139, 1), Array(140, 1), _ Array(141, 1), Array(142, 1), Array(143, 1), Array(144, 1), Array(145, 1), Array(146, 1), Array(147, 1), Array(148, 1), Array(149, 1), Array(150, 1)), _ TrailingMinusNumbers:=True s = 1 lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column While s <= lastColumn Cells(1, s).EntireColumn.Select If Cells(1, s) = "Original Data Source" Or Cells(1, s) = "Original Data Source Table/Field" Then Selection.Delete lastColumn = Cells(1, Columns.Count).End(xlToLeft).Column Else s = s + 1 End If Wend Range(Cells(1, s), Cells(1, s + 30)).EntireColumn.Select Selection.Delete MT = MT + 1 End If y = y + 1 Wend Worksheets("Launch").Activate Range("D28") = y - 2 Range("F28") = MT Range("D31") = Cd Application.ScreenUpdating = True Application.DisplayAlerts = True Application.DisplayStatusBar = True End Sub
有没有办法阻止VBA改变date,因为它是抛出所有的文件和解?
- 可视化基本date对象从具有索引的string中parsing
- 将DateTime.Now转换为在设置图表的最小比例尺时友好的值
- 在Visual Basic / Excel中处理date
- Exceldate – 8/11/2015 6:50:22.000 = 8/11/2015 6:50:22.000 = FALSE? 这里发生了什么?
- 从Excel中复制粘贴连接date时间值的格式与在Excel中看到的格式相同
- Excel:如何从excel行中获取date
- 来自文本string的VBA中的date格式
- 在数组中查找date范围 – Excel
- EPPlus Excel在1900.01.00之前使用DateTime报告