1

我正在使用下面的代码来刷新 HFM 工作表并更新 POV、Year 和 Period 中的两个变量。

我需要将“Period#Mar”中的“Mar”替换为单独工作表上的单元格内容(当前为“Mar”,但每个月都会更改)。

我试图创建一个范围对象,但 HypSetPOV 函数需要一个字符串,而不是一个范围。所以我不确定我是否需要以某种方式将我的范围转换为字符串,或者做一些不同的事情。

没有范围的代码(将期间更新为 Mar):

Sub HFM_Refresh()

Dim SheetName As String
Dim sts As Long
SheetName = "1 - PII PL Reporting Month"

ActiveWorkbook.Worksheets(SheetName).Visible = True
ActiveWorkbook.Worksheets(SheetName).Activate
ActiveWorkbook.Worksheets(SheetName).Range("A1").Activate

X = HypSetPOV(SheetName, "Year#2019", "Period#Mar")

sts = HypMenuVRefresh()

If sts <> 0 Then
MsgBox "Error - refresh not complete on worksheet " & SheetName
End If

End Sub

我尝试使用范围的代码(根本不更新期间):

Sub HFM_Refresh()

Dim SheetName As String
Dim sts As Long
Dim MonthMember As Range
SheetName = "1 - PII PL Reporting Month"
Set MonthMember = ActiveWorkbook.Worksheets("Update").Range("D9")

ActiveWorkbook.Worksheets(SheetName).Visible = True
ActiveWorkbook.Worksheets(SheetName).Activate
ActiveWorkbook.Worksheets(SheetName).Range("A1").Activate

X = HypSetPOV(SheetName, "Year#2019", "Period#MonthMember")

sts = HypMenuVRefresh()

If sts <> 0 Then
MsgBox "Error - refresh not complete on worksheet " & SheetName
End If

End Sub

提前致谢 :)

4

2 回答 2

1

You can do this:

X = HypSetPOV(SheetName, "Year#2019", _
              "Period#" & ActiveWorkbook.Sheets("Udatate").Range("D9").Value)
于 2019-07-29T16:21:46.210 回答
0

你可以使用REPLACE()

Sub HFM_Refresh()
Dim ws As Worksheet

Set ws = Worksheets("1 - PII PL Reporting Month")

ws.Visible = True

Dim replCell As Range, targetRng As Range
' replCell will be the cell you want to use
' to find the replacement.
Set replCell = ws.Range("A1")

' targetRng is the range of cells you want to
' replace `Period#Mar` with (or any other such
' string, like `Period#May`, etc.

Set targetRng = ws.Range("B1:B10")

Dim cel As Range
targetRng.Replace "Period#*", "Period#" & replCell.Value, xlPart

End Sub
于 2019-07-29T16:22:51.940 回答