excel - vba 输入公式引用另一个动态工作表中的单元格
问题描述
我正在尝试根据一年中的月份将公式输入到单元格中。我现在面临的问题是用于命名工作表的相同字符串无法很好地填充到公式中。我得到的是=Jan-'19'!N876
而不是='Jan-19'!N876
在牢房里。感谢是否有人可以提供帮助。谢谢!
Sub Summary()
Dim wb As Workbook
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim row As String
Dim newmth As String
newmth = Format(DateAdd("m", -1, Date), "mmm-yy")
row = 4
Set wb = ThisWorkbook
Set sht1 = wb.Sheets(newmth)
Set sht2 = wb.Sheets("Summary")
Application.ScreenUpdating = False
Do While sht2.Range("B" & (row)) <> ""
If sht2.Range("B" & (row)).Text = newmth Then
sht2.Range("D" & (row)).Formula = "=" & sht1.Name & "!" & "N876"
End If
row = row + 1
Loop
Application.ScreenUpdating = True
End Sub
解决方案
尝试sht2.Range("D" & (row)).Formula = "= '" & sht1.Name & "'!" & "N876"
推荐阅读
- javascript - 如何解决在 React 中循环浏览图像的减速问题?
- c# - 我不知道为什么我的程序要求多个输入
- vue.js - vue-meteor-tracker 未获取当前用户
- android - BottomNavigationView 中的选定项目与背景颜色相同
- lua - LUA 统计表中的条目数量
- android - 如何访问清单中声明的组件实例(广播接收器)
- java - 更新和删除不适用于使用 JAVAFx 的 mysql 数据库
- canvas - 将两个图像的差异绘制到画布上
- active-directory - 具有单向信任的跨林 LDAP 查询
- c# - 具有依赖注入的 DbProviderFactory