繁体   English   中英

在多个工作表上选择并自动填充单元格 - Excel VBA

[英]Select&autofill cells on multiple sheets - Excel VBA

我想在名为“ Arbeitsblatt XX ”的每个工作表中自动填充单元格中的数据$A$5:$A$37
我能够获得自动填充部分的一些代码以及在每个工作表中重复。
资料来源:

现在,结合我的编码模板几乎是成功的。 我只能在包括相关按钮的工作表上自动填充或者就像现在一样,正如您在下面的代码中看到的那样,我能够在每个工作表中选择所有相关单元格但没有自动填充。

我想它与缺少对工作表的引用有关,但我太愚蠢而无法检测到。 谢谢你的帮助。

            Sub FillDown()
            Dim xRng As Range
            Dim xRows As Long, xCols As Long
            Dim xRow As Integer, xCol As Integer

            Dim wsQ As Worksheet

            Set xRng = Selection
            Set currws = ActiveSheet

            Application.ScreenUpdating = False


            For Each wsQ In ThisWorkbook.Worksheets

             If Left(wsQ.Name, 12) = "Arbeitsblatt" Then
                    With wsQ
                     wsQ.Activate
                Cells(5, 1).Resize(33, 1).Select

                xCols = xRng.Columns.CountLarge
                xRows = xRng.Rows.CountLarge
            For xCol = 1 To xCols
              For xRow = 1 To xRows - 1
                If xRng.Cells(xRow, xCol) <> "" Then
                  xRng.Cells(xRow, xCol) = xRng.Cells(xRow, xCol).Value
                  If xRng.Cells(xRow + 1, xCol) = "" Then
                    xRng.Cells(xRow + 1, xCol) = xRng.Cells(xRow, xCol).Value
                  End If
                End If
              Next xRow
            Next xCol
            currws.Activate

                     End With
                End If
            Next wsQ

            Application.ScreenUpdating = True
            End Sub

我感到非常难过,看到有你的问题没有答案或建议呢。 请让我试着帮忙。

我喜欢简单的代码,因此我尝试使用Excel提供的.AutoFill方法。 请参阅下面的代码,我在示例工作簿上测试过:

Sub FillDown()
Dim wsQ As Worksheet

    For Each wsQ In ThisWorkbook.Sheets
        If Left(wsQ.Name, 12) = "Arbeitsblatt" Then
            With wsQ
            .Activate
            .Range("A5").AutoFill Destination:=Range("A5:A37") 'this is the autofill which starts autofilling from A5 cell and ends in A37 cell
            .Range("A5:A37").Select
            End With
        End If
    Next wsQ

End Sub

我不确定你究竟要尝试自动填充什么,因此这个简单的代码可能也可能不够。 如果您可以提供更多信息(例如,您尝试自动填充哪些数据,以及它是否始终从A5开始,或者单元格是否已经填满一半,您只需要完成其余的等等)

请让我知道结果,以便我或其他人可以提供进一步的帮助。 谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM