使用vba格式化Excel数据库标头

时间:2022-03-29 15:58:12

I have an excel table and I want to extract a portion of the columns names: for example, the column name is "Y2014", I should get the String (or integer) "2014" only here is my code

我有一个excel表,我想提取一些列名称:例如,列名称是“Y2014”,我应该得到字符串(或整数)“2014”只有这里是我的代码

Function findValue(year As String)
Dim formattedYear As String
formattedYear = Microsoft.VisualBasic.Right(year, 1)
findValue = formattedYear
End Function

I get an error of value either if I try with a simple value doing findValue("Y2014") of if I try with the cell value findValue(Q1) (where A1 content is equivalent to "Tableau1[[#En-têtes];[Y2014]])": can someone help? thanks.

如果我尝试使用findValue(“Y2014”)的一个简单值,如果我尝试使用单元格值findValue(Q1)(其中A1内容相当于“Tableau1 [[#En-têtes]; [Y2014]])“:有人可以帮忙吗?谢谢。

2 个解决方案

#1


0  

First impression looking at your code is that functions always return a value so you have to specify what type the function returns like

查看代码的第一印象是函数总是返回一个值,因此您必须指定函数返回的类型

Function findValue(year As String) as string

函数findValue(year As String)作为字符串

What sort of error are you getting?

你得到什么样的错误?

#2


0  

I just had to get rid of the Microsoft.VisualBasic. mention

我只是摆脱了Microsoft.VisualBasic。提到

#1


0  

First impression looking at your code is that functions always return a value so you have to specify what type the function returns like

查看代码的第一印象是函数总是返回一个值,因此您必须指定函数返回的类型

Function findValue(year As String) as string

函数findValue(year As String)作为字符串

What sort of error are you getting?

你得到什么样的错误?

#2


0  

I just had to get rid of the Microsoft.VisualBasic. mention

我只是摆脱了Microsoft.VisualBasic。提到