根据sheet1指定行数往sheet2中写数据

Dim i As Integer

Sub addNewInfo(ByVal stext As String, ByVal icount As String)
   Worksheets("Sheet2").Activate
   Dim rowcount As Integer
   Dim j, m As Integer
   j = Val(icount)
   rowcount = ActiveSheet.UsedRange.Rows.Count
   For m = 0 To j
       ActiveSheet.Cells(rowcount, 1).Value = stext
       rowcount = rowcount + 1
   Next
  
End Sub

Private Sub CommandButton1_Click()
    Worksheets("Sheet1").Activate
    Dim rowcount As Integer
   
    Dim stext, icount As String
    icount = 0
    rowcount = ActiveSheet.UsedRange.Rows.Count
   
    For i = 2 To rowcount
      Worksheets("Sheet1").Activate
      stext = ActiveSheet.Cells(i, 1).Value
      icount = ActiveSheet.Cells(i, 2).Value
      Call addNewInfo(stext, icount)
    Next
End Sub

posted @ 2013-01-25 10:00  骑着骆驼逛沙漠  阅读(248)  评论(0编辑  收藏  举报