[英]After copy and paste values from one workbook to another, a formula doesn't work with a specific range until I doubleClick cells
Using VBA I open one workbook, copy data and paste it to another workbook.使用 VBA 打开一个工作簿,复制数据并将其粘贴到另一个工作簿。 In the second workbook I set a formula for specific range of custom format of values(dd/mm/yyyy hh:mm) but the formula doesn't work.在第二个工作簿中,我为特定范围的自定义值格式(dd/mm/yyyy hh:mm)设置了一个公式,但该公式不起作用。 Values are kept on the left side of cells as a text with custom format until I double click.值作为具有自定义格式的文本保存在单元格的左侧,直到我双击为止。 Format in both workbooks(worksheets) is the same and I want to keep it.两个工作簿(工作表)中的格式相同,我想保留它。
I've been trying fix it using:我一直在尝试使用以下方法修复它:
range.TextToColumns Destination:=range DataType:=xlFixedWidth FieldInfo:=Array(Array(0,9),Array(1,1), Array(16,9))
It works within halfway.它在中途工作。 Date is fit to the right side of cells but my day from custom date is 17 days less???:D When I omit Array(0,9) it returns additional date 02/01/1990 and my original date is moved to the next column.日期适合单元格的右侧,但我的自定义日期比自定义日期少 17 天???:D 当我省略 Array(0,9) 它返回额外的日期 02/01/1990 并且我的原始日期被移动到下一栏。
Has anyone got any solution?有没有人有任何解决方案? How exactly does.TextToColumns work? .TextToColumns 究竟是如何工作的? How Can I correctly declare arg for FieldInfo to receive original date and fit it to the right side of cells?如何正确声明 FieldInfo 的 arg 以接收原始日期并将其放置在单元格的右侧?
below is an example of how to convert a date that is in text format (cell B1) to an actual date.下面是如何将文本格式的日期(单元格 B1)转换为实际日期的示例。 Notice how a text format is left aligned and a date format is right aligned.请注意文本格式是如何左对齐的,而日期格式是如何右对齐的。
Keep in mind that a date is a number-> the integer part is the date and the decimal part is the time.请记住,日期是一个数字-> integer 部分是日期,小数部分是时间。
Public Sub sTestDate()
Dim v As Variant
v = Sheet1.Range("B1").Value
Sheet1.Range("B2").Value = CDbl(CDate(v))
Sheet1.Range("B3").Value = CDbl(CDate(v))
Sheet1.Range("B3").NumberFormat = "dd/mm/yyyy hh:mm"
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.