excel - 用循环功能替换输入框
问题描述
所以我想创建一个循环函数 -
如果列 O 中的响应为“是”,则输入列 C 中的值作为复制工作表的“新名称”循环,直到列 O 为空白
我知道我必须删除输入框(“输入复制的工作表的名称”)
但是我不确定在 newname 之后放置什么作为循环函数
Sub Button112_Click()
Dim newName As String
On Error Resume Next
newName = InputBox("Enter the name for the copied worksheet")
If newName <> "" Then
ThisWorkbook.Sheets("Template").Copy After:=Worksheets(Sheets.Count)
On Error Resume Next
ActiveSheet.Name = newName
Range("$D$3").Value = newName
End If
Dim n As Name
For Each n In ActiveWorkbook.Names
n.Visible = True
Next n
Dim numrow
numrow = Range("F16").Value
If IsNumeric(numrow) Then
For i = 1 To numrow
Call INRW
Next i
End If
End Sub
我尝试过类似的方法,但没有成功
lastRow = .Cells(Rows.Count, 15).End(xlUp).Row
For i = 1 To lastRow
If .Cells(i, 15).Value2 = "Yes" Then CopySheetAndRename (.Cells(i, 3).Value2)
Next i
End With
End Sub
解决方案
我猜你喜欢这样的事情:
Sub Button112_Click()
Dim lastRow As Long, i As Long
With Worksheets("mySheetName")'change mySheetName to suit your needs
lastRow = .Cells(Rows.Count, 15).End(xlUp).Row
For i = 1 To lastRow
If .Cells(i, 15).Value2 = "Yes" Then
ThisWorkbook.Sheets("Template").Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = .Cells(i, 3).Value2
Range("$D$3").Value = .Cells(i, 3).Value2
End If
Next
End With
....
rest of your code
推荐阅读
- elasticsearch - 在 ELK 中配置 number_of_shards 和 number_of_replicas
- python - Python While循环无限
- forms - Symfony 表单渲染过早显示错误
- python - tkinter - 使用 wm_manage 和 wm_forget 停靠和取消停靠框架
- java - 为什么 vavr 的 Function1 不接受 Seq
类接受 Seq ? - java - 调整 JLabel 大小以适应调整大小的主 JPanel
- python - 在“原子”块结束之前,您无法执行查询
- angular - 剑道网格内的剑道树视图
- javascript - 如何在 Angular 中为响应式表单构建可重用字段
- c++ - ROS问题:如何用opencv4正确编译自定义cv_bridge