Sub ChangeTime_Click()
'
'功能:改变时间
'

Dim rc As Integer
'获取EXCEL中有内容的数据行数
rc = ActiveSheet.UsedRange.Rows.Count

For i = 1 To rc
  '内容不为空时---没实现完整性检查
  If Range("A" & i).Value <> "" Then
     '时间加一个月
     Range("A" & i).Value = DateAdd("m", 1, Range("A" & i).Value)
  End If
Next i

'根据选中区域,每行时间类型的数据自动加一个月
Dim row1 As Integer, col1 As Integer
  Dim row2 As Integer, col2 As Integer
  '选中的单元格区域的开始行坐标
  row1 = Range(Selection.Address).Row
  '选中的单元格区域的结束行坐标
  row2 = Range(Selection.Address).Rows.Count + row1 - 1
  '选中的单元格区域的开始列坐标
  col1 = Range(Selection.Address).Column
  '选中的单元格区域的结束列坐标
  col2 = Range(Selection.Address).Columns.Count + col1 - 1
 
  '遍历选中单元格区域的单元格
  For i = row1 To row2
      For ii = col1 To col1
     
        If Cells(i, ii).Value <> "" Then
         '时间类型的区域值为每月加1
          Cells(i, ii).Value = DateAdd("m", 1, Cells(i, ii).Value)
       End If
      Next ii
  Next i
 
  MsgBox "起始坐标:" & row1 & "," & col1 & "终止坐标:" & row2 & "," & col2


End Sub

posted on 2010-02-10 17:54  大鱼  阅读(1264)  评论(0编辑  收藏  举报