vba excel 的宏

Sub Macro2()
'
' Macro2 Macro
'
' 快捷键: Ctrl+s
'

Dim I1 As Integer
I1 = 1
Sheets("Sheet2").Cells.ClearContents

For I = 2 To Range("a65536").End(xlUp).Row
s = Worksheets("Sheet1").Cells(I, 1)
If Len(s) > 20 Then
I1 = I1 + 1
Sheet2.Cells(I1, 1) = Worksheets("Sheet1").Cells(I, 1)
Sheet2.Cells(I1, 1).HorizontalAlignment = xlCenter
Sheet2.Cells(I1, 1).VerticalAlignment = xlCenter

Sheet2.Cells(I1, 2) = Worksheets("Sheet1").Cells(I, 2)
Sheet2.Cells(I1, 2).HorizontalAlignment = xlCenter
Sheet2.Cells(I1, 2).VerticalAlignment = xlCenter

Sheet2.Cells(I1, 3) = Worksheets("Sheet1").Cells(I, 3)
Else

Sheet2.Cells(I1, 4) = Sheet2.Cells(I1, 4) + Worksheets("Sheet1").Cells(I, 1) + "、"
 Sheet2.Cells(I1, 4).HorizontalAlignment = xlCenter
 Sheet2.Cells(I1, 4).VerticalAlignment = xlCenter

End If

 

Next

 

Sheet2.[A1].Resize(1, 1).Value = "保单号"
Sheet2.[A1].HorizontalAlignment = xlCenter
Sheet2.[A1].VerticalAlignment = xlCenter
Sheet2.[B1].Resize(1, 1).Value = "案件数量"
Sheet2.[B1].HorizontalAlignment = xlCenter
Sheet2.[B1].VerticalAlignment = xlCenter
Sheet2.[c1].Resize(1, 1).Value = "理赔金额"
Sheet2.[c1].HorizontalAlignment = xlCenter
Sheet2.[c1].VerticalAlignment = xlCenter
Sheet2.[d1].Resize(1, 1).Value = "出险地点"
Sheet2.[d1].HorizontalAlignment = xlCenter
Sheet2.[d1].VerticalAlignment = xlCenter


 MsgBox ("执行完毕")
 
 Sheets("Sheet2").Copy '把宏所在工作簿的Sheet1表复制到新工作簿中

ActiveWorkbook.SaveAs Filename:="C:\Users\lz311\Desktop\保单号出险城市对应表.xlsx" '保存新工作簿

 Workbooks("保单号出险城市对应表.xlsx").Close (True)

End Sub


 

你可能感兴趣的:(vba excel 的宏)