调整本月的代码

时间:2018-07-25 14:08:36

标签: vba excel-vba

早上好

我有一个可提取季度报告以运行宏的代码,但是我遇到了更改定义​​月份的问题。在用于宏的报告中,它包含月份,并可能会发生变化。如何调整代码以切换月份。

 Dim Quarter As String
 Dim Month As String
 Dim SIFile As String
 Dim SIData As String
 Dim SiName As String
 Dim FiName As String
 Dim MyQtr As String
 'Defining the worksheet variables and the worksheet name
 Sheets("Summary").Select
 Range("X4").Select
 Quarter = Range("X4").Value
 MyQtr = Range("AA4").Value

 Range("Z4").Select
 Month = Range("Z4").Value

 SIFile = Quarter & "_si_allocation_audit__mar__6_decimal_detail_sjmc.txt"
 SiName = Quarter & "_si_allocation_audit__mar__"

1 个答案:

答案 0 :(得分:0)

假设mar是月份,并且该值来自Z4并且已经缩写,那么您将保存一个变量(由于函数不被称为Month)并连接到文件的字符串中,等等。

Dim monthAbbr As String
monthAbbr = Range("Z4").Value
SIFile = Quarter & "_si_allocation_audit__" & monthAbbr &  "__6_decimal_detail_sjmc.txt"