For loop in excel VBA

前端 未结 2 2016
轻奢々
轻奢々 2021-01-20 09:27

Im trying to use For loop on an excel column. This is my code:

   For Each c In Worksheets(\"sheet1\").Range(\"A1:A5000\").Cells
        c.Offset(0, 1).Range         


        
相关标签:
2条回答
  • 2021-01-20 10:07
    Dim RowIndex As Long
    RowIndex = 1
    
    Dim c
    
    While Not IsEmpty(Worksheets("sheet1").Cells(RowIndex, 1))
        Set c = Worksheets("sheet1").Cells(RowIndex, 1)
        c.Offset(0, 1).Range("A1").Value = Right((Left(c, 13)), 7)
        RowIndex = RowIndex + 1
    Wend
    
    0 讨论(0)
  • 2021-01-20 10:12

    You may try this ...

    Dim r As Range
    
    Set r = Range("A65536").End(xlup)
    
    For Each c In Worksheets("sheet1").Range("A1:" & r.Address).Cells
       c.Offset(0, 1).Range("A1").Value = Right((Left(c, 13)), 7)
    Next
    
    0 讨论(0)
提交回复
热议问题