0
選擇多個列運行腳本下面的腳本轉換存儲爲文本到m/d/yyyy格式經由輸入框
然而日期的列,這僅與1列的工作原理。
我想讓用戶能夠選擇多列,用逗號分隔併產生相同的結果。
任何指針將不勝感激。
Sub DateFixer()
'place this script in your personal macro workbook and assign to button
'converts column of dates stored as text to m/d/yyyy format
'set input dims
Dim MySheet As Worksheet
Dim MyRange As Range, MyCell As Range
Dim MyPrompt As String
Dim MyTitle As String
'set input box dims
MyPrompt = "Please select dates column (1 column only)"
MyTitle = "Convert text to dates"
'error handling
On Error GoTo OuttaHere
'capture range
Set MyRange = Application.InputBox(MyPrompt, MyTitle, Type:=8)
Set MySheet = MyRange.Worksheet
MyColumn = MyRange.Column
LastRow = MySheet.UsedRange.Rows.Count
With MySheet
Set MyRange = .Range(.Cells(1, MyColumn), .Cells(LastRow, MyColumn))
MyRange.NumberFormat = "m/d/yyyy"
For Each MyCell In MyRange
MyCell.Formula = MyCell.Value
Next
End With
OuttaHere:
End Sub