如何在 Visual Basic 中从 B 列读取 Excel 单元格中的工作表“控件”直到一个空单元格?
之后,我想为每个单元格生成一个名称来自单元格的新工作表。在这:
:
您会看到本专栏的内容,有时可能会有所不同。读完后,我想生成名称为: 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/