|
3#
楼主 |
发表于 2009-6-10 21:13:20
|
只看该作者
你是我见过的真正的高手,佩服得六体投地,在你的指导下,我已将宏重新修改,自动打开宏标卡(在你的电脑上路径要修改一下),可以识别不同的文件名,但是运行错误在Selection.AutoFilter处,不知所以,请不吝赐教再指点,最好是全部源码,你真是个好人!!
Sub Macro1()
'
' Macro1 Macro
' 宏由 黄勇 录制,时间: 2009-6-10
'
' 快捷键: Ctrl+k
Dim strA As String
strA = ThisWorkbook.Name
ChDir "C:\Documents and Settings\Administrator\My Documents\宏标卡"
Workbooks.Open Filename:= _
"C:\Documents and Settings\Administrator\My Documents\宏标卡\门店标卡(武汉).xls"
Windows(strA).Activate
Range("A2").Select
Selection.Insert Shift:=xlDown
Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="1"
Cells.Select
Range("A2").Activate
Selection.Copy
Sheets.Add
ActiveSheet.Paste
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Range("B2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'[门店标卡(武汉).xls]品类对应部门'!C1:C2,2,0)"
Selection.AutoFill Destination:=Range("B2:B100"), Type:=xlFillDefault
Range("B2:B100").Select
ActiveWindow.SmallScroll Down:=-84
Range("B1").Select
Selection.AutoFilter
Selection.AutoFilter Field:=2, Criteria1:="<>#N/A", Operator:=xlAnd
Cells.Select
Range("B1").Activate
Selection.Copy
Sheets("Sheet1").Select
Sheets.Add
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Sheet2").Select
Sheets.Add
Application.CutCopyMode = False
Selection.Consolidate Sources:= _
"'Sheet2'!R1C2:R148C136" _
, Function:=xlSum, TopRow:=True, LeftColumn:=True, CreateLinks:=False
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Range("B2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],'[门店标卡(武汉).xls]品类对应部门'!C2:C3,2,0)"
Selection.AutoFill Destination:=Range("B2:B12"), Type:=xlFillDefault
Range("B2:B12").Select
Range("A1").Select
ActiveCell.FormulaR1C1 = "品类"
Range("B1").Select
ActiveCell.FormulaR1C1 = "序号"
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin
Rows("1:22").Select
Selection.Copy
Sheets.Add
Sheets("Sheet4").Select
ActiveWindow.SmallScroll Down:=-15
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Range("A1").Select
Sheets("Sheet4").Select
Sheets.Add
Range("A1").Select
ActiveCell.FormulaR1C1 = "='[门店标卡(武汉).xls]门店顺序'!RC"
Range("A1").Select
Selection.AutoFill Destination:=Range("A1:C1"), Type:=xlFillDefault
Range("A1:C1").Select
Selection.AutoFill Destination:=Range("A1:C100"), Type:=xlFillDefault
Range("A1:C100").Select
ActiveWindow.SmallScroll Down:=-135
Sheets("Sheet4").Select
Range("B1:K1").Select
Selection.Copy
Sheets("Sheet5").Select
Range("D1").Select
ActiveSheet.Paste
Range("D2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,2,0)"
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,2,0)/10000"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:M2"), Type:=xlFillDefault
Range("D2:M2").Select
ActiveWindow.ScrollColumn = 1
Range("E2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,3,0)/10000"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,4,0)/10000"
Range("G2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,5,0)/10000"
Range("H2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,6,0)/10000"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,7,0)/10000"
Range("J2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,8,0)/10000"
Range("K2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,9,0)/10000"
Range("L2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,10,0)/10000"
Range("M2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet4!C1:C11,11,0)/10000"
Range("D2:M2").Select
Range("M2").Activate
ActiveWindow.ScrollColumn = 4
Selection.AutoFill Destination:=Range("D2:M100"), Type:=xlFillDefault
Range("D2:M100").Select
Cells.Select
Range("M2").Activate
ActiveWindow.ScrollColumn = 1
ActiveWindow.SmallScroll Down:=-126
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Selection.Replace What:="#N/A", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
ActiveWindow.ScrollColumn = 1
With Selection.Font
.Name = "宋体"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.NumberFormatLocal = "0.00_ "
ActiveWindow.ScrollColumn = 1
Columns("A:C").Select
Selection.Replace What:="0", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
ActiveWindow.ScrollColumn = 4
ActiveWindow.SmallScroll ToRight:=2
Range("N1").Select
ActiveCell.FormulaR1C1 = "合计"
Range("N2").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-10]:RC[-1])"
Range("N2").Select
Selection.AutoFill Destination:=Range("N2:N42"), Type:=xlFillDefault
Range("A43").Select
ActiveCell.FormulaR1C1 = "合计"
Range("D43").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-41]C:R[-1]C)"
Range("D43").Select
ActiveWindow.SmallScroll Down:=3
Range("D43").Select
Selection.AutoFill Destination:=Range("D43:N43"), Type:=xlFillDefault
Range("D43:N43").Select
ActiveWindow.SmallScroll Down:=-42
ActiveWindow.ScrollColumn = 1
Sheets("Sheet5").Select
Sheets("Sheet5").Name = "报表"
Sheets("Sheet4").Select
ActiveWindow.SelectedSheets.Visible = False
ActiveWindow.SelectedSheets.Visible = False
ActiveWindow.SelectedSheets.Visible = False
ActiveWindow.SelectedSheets.Visible = False
Sheets("报表").Select
End Sub |
|