How to execute a function for each cell in a column and loop through all workbooks?

后端 未结 1 1879
既然无缘
既然无缘 2021-01-04 19:32

Here\'s what I have so far:

Sub TrimColumnD()
   Dim ws As Worksheet

   For Each ws In ThisWorkbook.Worksheets
   Dim c As Range
        For Each c In Activ         


        
相关标签:
1条回答
  • 2021-01-04 20:06

    Please change this line:

    For Each c In ActiveSheet.UsedRange.Columns("D").Cells
    

    into this one:

    For Each c In ws.UsedRange.Columns("D").Cells
    

    In your code internal loop refers to activesheet while it should refer to ws variable representing sheet.

    0 讨论(0)
提交回复
热议问题