首页 文章

Excel工作表单元格到不同的工作表

提问于
浏览
-1

我需要找到一个脚本,允许我使用工作簿中索引表的信息 .

  • 我需要它来获取A3:G304范围内的数据 .

  • 数据将分散到各自的表格中 .

  • 工作表以A列中的值命名,需要按照以下A到A1放置在单元格中; B到A2; C到A3; D到B3; E到C3; F到E2; G到G2 .

  • 每行对应不同的表格 .

先感谢您

1 回答

  • 0

    这是您需要的代码:

    Dim targetSheet As Worksheet
    Dim rowIndex, columnCount As Integer
    
    Set targetSheet = ActiveSheet
    columnCount = UBound(initialRange, 2)
    
    
    For rowIndex = 3 To 304
        Set targetSheet = Sheets.Add(After:=targetSheet)
        ' The (Row #) is added to sheet name to prevent Workbook from having duplicated name sheets
        ' Remove if not applicable
        targetSheet.Name = Cells(rowIndex, "A").Value & " (Row " & rowIndex & ")"
    
        Cells(rowIndex, "A").Resize(1, 7).Copy
        targetSheet.Cells(columnCount, "A").End(xlUp).PasteSpecial Transpose:=True
        Application.CutCopyMode = False
    Next rowIndex
    

    唯一的问题是Excel可能会耗尽超过300个WorkSheets的资源 .

相关问题