gpt4 book ai didi

excel - 运行时错误 9 下标超出范围

转载 作者:行者123 更新时间:2023-12-04 20:44:05 24 4
gpt4 key购买 nike

我对 VB for Excel 有点陌生,但我希望在接下来的几个月里会变得更好。它可以通过多种方式使我的团队的工作更轻松。有人可以帮我弄清楚如何让这个宏运行吗?我已经解决了一些问题,但欢迎任何专业知识。

我正在尝试创建一个人们可以用人口普查数据填写的表格,然后我将在另一张表中使用这些数据运行公式。

我目前在“Sheets(strName).Select”部分收到突出显示的错误

Sub InputSheet()

Dim sName As String
Dim sStatus As String
Dim sSalary As String
Dim sBonus As String
Dim sPartner As String
Dim sWorkState As String
Dim sBenefitsLevel As String

sName = InputBox("Input Employee Name:", "PROJECT INFORMATION")
sStatus = InputBox("Input FT or PT:", "PROJECT INFORMATION")
sSalary = InputBox("Input Salary:", "PROJECT INFORMATION")
sBonus = InputBox("Input Bonus:", "PROJECT INFORMATION")
sPartner = InputBox("Input Partner Status (Y/N):", "PROJECT INFORMATION")
sWorkState = InputBox("Input Work State:", "PROJECT INFORMATION")
sBenefitsLevel = InputBox("Input Benefits Level:", "PROJECT INFORMATION")


Dim MyNewSheet As Worksheet
Set MyNewSheet = Worksheets.Add(, Sheets(Sheets.Count))
Dim strName As String
strName = "Project Data "

Sheets(strName).Select
Cells(1, 1).Value = "Employee Name or Title"
Cells(1, 2).Value = "Employment Status"
Cells(1, 3).Value = "Salary"

Cells(1, 4).Value = "Bonus"
Cells(1, 5).Value = "Partner Status"
Cells(1, 6).Value = "Work State"
Cells(1, 7).Value = "Benefits Level"
Cells(2, 1).Value = sName
Cells(2, 2).Value = sStatus
Cells(2, 3).Value = sSalary
Cells(2, 4).Value = sBonus
Cells(2, 5).Value = sPartner
Cells(2, 6).Value = sWorkState
Cells(2, 7).Value = sBenefitsLevel
ThisWorkbook.Save

MsgBox "Process is Complete!"

End Sub

最佳答案

您在 strName 末尾有一个空格 - 选项卡名为“项目数据”还是“项目数据”?

关于excel - 运行时错误 9 下标超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23549447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com