从访问中格式化一个Excel文本字段。

时间:2023-02-09 20:26:22

I have a string like "Saturday, November 28, 2015 11:59:59 PM GMT-5" in an Excel spreadsheet and would like to remove the Day of the week and Time Zone before importing it to Access using VBA. I tried :

我有一个类似于“周六,11月28日,2015年11:59:59 PM GMT-5”的字符串在Excel电子表格中,我想在导入之前删除星期和时区,然后使用VBA访问它。我试着:

ExcelWorksheet.Cells(1 + counter, nIdCol) = left((ExcelWorksheet.Cells(1 + counter, nIdCol)), Find(" GMT", ExcelWorksheet.Cells(1 + counter, nIdCol) - 1)) "

ExcelWorksheet。单元格(1 + counter, nIdCol) =左侧(ExcelWorksheet)。单元格(1 + counter, nIdCol), Find(“GMT”,ExcelWorksheet。细胞(1 +计数器,nIdCol) - 1)”

but found that "Find" is not an Access function.

但发现“查找”不是一个访问函数。

Any idea to do it?

有什么办法吗?

2 个解决方案

#1


1  

If you want to do it in Excel, before importing to Access with VBA, you can use this formula to trim them. Note: I'm assuming that each of your strings will have "GMT" at the end to denote the time zone, and will have a , after the day of the week.

如果您想在Excel中完成,在导入VBA之前,您可以使用这个公式对它们进行修剪。注意:我假设您的每一个字符串在最后都有“GMT”来表示时区,并且在一周之后会有一个“GMT”。

If Saturday, November 28, 2015 11:59:59 PM GMT-5 is in A1, use this formula in B1:

如果2015年11月28日(周六)11:59:59 PM GMT-5在A1中,使用B1中的公式:

=TRIM(MID(A1,SEARCH(", ",A1)+1,SEARCH("GMT",A1)-SEARCH(", ",A1)-2))

=修剪(中期(A1、搜索(”、“A1)+ 1,搜索(格林尼治时间,A1)搜索(”、“A1)2))

#2


0  

Try using the Instr() function. Replace Find("GMT") with

尝试使用Instr()函数。取代找到(格林尼治时间)

Instr(string:=ExcelWorksheet.Cells(1 + counter, nIdCol).Value, substring:="GMT") - 1

More on the Instr() function: http://www.techonthenet.com/excel/formulas/instr.php

更多关于Instr()函数的信息:http://www.techonthenet.com/excel/formula as/提高

#1


1  

If you want to do it in Excel, before importing to Access with VBA, you can use this formula to trim them. Note: I'm assuming that each of your strings will have "GMT" at the end to denote the time zone, and will have a , after the day of the week.

如果您想在Excel中完成,在导入VBA之前,您可以使用这个公式对它们进行修剪。注意:我假设您的每一个字符串在最后都有“GMT”来表示时区,并且在一周之后会有一个“GMT”。

If Saturday, November 28, 2015 11:59:59 PM GMT-5 is in A1, use this formula in B1:

如果2015年11月28日(周六)11:59:59 PM GMT-5在A1中,使用B1中的公式:

=TRIM(MID(A1,SEARCH(", ",A1)+1,SEARCH("GMT",A1)-SEARCH(", ",A1)-2))

=修剪(中期(A1、搜索(”、“A1)+ 1,搜索(格林尼治时间,A1)搜索(”、“A1)2))

#2


0  

Try using the Instr() function. Replace Find("GMT") with

尝试使用Instr()函数。取代找到(格林尼治时间)

Instr(string:=ExcelWorksheet.Cells(1 + counter, nIdCol).Value, substring:="GMT") - 1

More on the Instr() function: http://www.techonthenet.com/excel/formulas/instr.php

更多关于Instr()函数的信息:http://www.techonthenet.com/excel/formula as/提高