2016-10-11 174 views
-1
Sub table() 

Dim ws As Worksheet 

    For Each ws In ActiveWorkbook.Worksheets 

    ws.Cells(1, "C") = Format(ws.Cells(1, "A"), "yyyymmdd") & Format(ws.Cells(1, "B"), "hhmmss") 
    ws.Cells(1, "C").NumberFormat = "0" 
    Next ws 

End Sub 

这是我的单细胞(第一个细胞)代码。我想通过为我放置循环来运行多个单元格。如何在excel中为许多单元添加循环

回答

0

做这样的事情:

For Each ws In ActiveWorkbook.Worksheets 
    for each cell in ws.range("C1:C1000") 
     cell = Format(ws.Cells(1, "A"), "yyyymmdd") & Format(ws.Cells(1, "B"), "hhmmss") 
     cell.NumberFormat = "0" 
    next cell 
Next ws 
+0

对不起,先生代码是行不通的。 //// cell.NumberFormat =“0”/////行显示错误。 错误是需要的对象 你已经在第3行写了更多东西////ws.cells(1,"A"),"yyyymmdd“ 1是针对1个单元的。我想通过所有单元遍历它。 –

1
Sub table() 
Dim ws As Worksheet 
    For Each ws In ActiveWorkbook.Worksheets 
     For i = 1 To 500 ' <-- Edit these numbers to modify the size of the iteration 
      ws.Cells(i, "C") = Format(ws.Cells(i, "A"), "yyyymmdd") & Format(ws.Cells(i, "B"), "hhmmss") 
      ws.Cells(i, "C").NumberFormat = "0" 
     Next i 
    Next ws 
End Sub 
+0

thnks buddy其工作 –

+0

如果您的问题已解决,请使用答案旁边的复选标记将其指明给其他读者。 :) – Vegard

相关问题