vba - 逐个读取单元格并创建工作表

标签 vba excel

如何在 Visual Basic 中从 B 列读取 Excel 单元格中的工作表“控件”直到一个空单元格?

之后,我想为每个单元格生成一个名称来自单元格的新工作表。在这:

picture :

您会看到本专栏的内容,有时可能会有所不同。读完后,我想生成名称为: RW_BONDS, ... 的空工作表。

最佳答案

你可以做这样的事情。

Private Sub CommandButton1_Click()
Dim ws As Excel.Worksheet
Dim lRow As Long
Dim lastRow  As Long

    'Set the sheet to read from
    Set ws = Application.Sheets("control") 

    'Set the row to start reading at
    lRow = 3

    lastRow = wsOwners.Cells(wsOwners.Rows.Count, "B").End(xlUp).Row

    'Loop through the rows
    Do While lRow <= lastRow

        If ws.Range("B" & lRow).Value <> "" then

            'Add a new sheet
            ActiveWorkbook.Sheets.Add Before:=Worksheets(Worksheets.Count)

            'Change the name to the value of column B in the current row
            ActiveWorkbook.ActiveSheet.Name = ws.Range("B" & lRow).Value

        End If

    'Increment your row to the next one
    lRow = lRow + 1

    Loop

End Sub

关于vba - 逐个读取单元格并创建工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33959237/

相关文章:

excel - 如何使用VBA保存分号分隔的csv文件?

Excel公式获取一个单元格中的所有值

excel - 如何使用索引查找所有大于的值

excel - 数组中具有条件值的计数公式

vba - 使用复制函数 VBA 时应用程序定义或对象定义的错误

VBA 调试——查看所有打开的 DAO 记录集

vba - 在任何打开的工作簿中检测刚刚停用的工作表中的选择类型

arrays - 当使用字符串数组作为输入时,TEXTSPLIT 结合 BYROW 返回意外结果

excel - 引用另一个在单独窗口中打开的工作簿的方法是什么?

excel - VBA停止在excel 2010中打印工作表