简体   繁体   English

将值从一个工作簿复制并粘贴到另一个工作簿后,在我双击单元格之前,公式不适用于特定范围

[英]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.

相关问题 将单元格范围从一个工作簿复制到另一个工作簿 - Copy range of cells from one workbook to another VBscript:将数据从一个工作簿复制/粘贴到另一工作簿的下一个空白行(特定单元格) - VBscript: Copy/Paste data from one workbook to next blank row (specific cells) of another workbook 如何使用C#将一个Excel工作簿中特定范围的单元格复制到另一工作簿中 - how to copy cells from a specific range from one excel workbook to another workbook using c# Openpyxl - 将单元格范围(带公式)从工作簿复制到另一个 - Openpyxl - Copy range of cells(with formula) from a workbook to another 如何使用 VBA 将基于某些条件的粘贴数据从一个工作簿复制到另一个工作簿(特定单元格)? - How to copy paste data based on some criterias from one workbook to another(specific cells) using VBA? 如何从另一个工作簿复制一系列单元格并将其粘贴到另一个工作簿? - How to copy a range of cell from another workbook and paste it to another one? 如何复制一系列公式值并将它们粘贴到另一个工作表中的特定范围? - How do I copy a range of formula values and paste them to a specific range in another sheet? 复制列中的单元格范围,直到空白单元格,然后粘贴到新工作簿中 - Copy range of cells in column until blank cell, and paste into new workbook 范围声明以从一个工作簿复制并粘贴到另一个工作簿 - Range declarations to copy from one workbook and paste to another 将粘贴自动范围从一个工作簿复制到另一个工作簿 - copy paste automatic range from one workbook to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM