excel - 如何从 VLookup 返回值中保留日期格式?

标签 excel vba formatting vlookup

我有一张混合格式数据(日期、 double 、字符串等)的表格。
我在 lookup_range 中搜索值(my_index),我想检索数据以更改其他工作表中的单元格。它工作正常,但是当 VLookup 返回的值是日期并且我将其设置到另一张表时,它会丢失其日期格式。

Dim lookup_range As Range
Dim my_index, my_value As Variant

my_value = Application.VLookup(my_index, lookup_range, num_col, False)
Sheets(3).Cells(num_row, last_col_s1 + num_col - 1).Value = my_value

所以,当lookup_range中的数据是02/05/2014表 3 中显示的数据类似于 41761 .

我需要保留lookup_range中数据的原始数据格式。

最佳答案

VLOOKUP不关心它返回的数据的格式 - 它返回数据,而不是格式。

确保与源格式相同的唯一方法是手动或以编程方式复制/粘贴该格式。

关于excel - 如何从 VLookup 返回值中保留日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28859172/

相关文章:

vba - 在自定义数字格式 VBA 中使用变量

php - 如何从 PHP 输出格式化的 HTML?

colors - 基于列值的 Spotfire 行颜色

parsing - Excel解析单元格值

vba - 在Excel中复制格式的快速方法

python - 输出/打印 "readable"字典

php - xlsb 文件下载不可读的内容错误与 ms excel 2007

vba - 使用 VBA 设置图表数据标签格式

excel - 如何解决错误代码: '404' ,消息: 'The requested resource doesn' t exist when adding a row to an excel file using azure logic apps?

excel - 如何使用 Worksheet_Change 函数找到的表中的值自动填充电子邮件正文