码迷,mamicode.com
首页 > 其他好文 > 详细

excel_VB宏脚本_批量生成点餐宝接受的格式

时间:2015-12-28 20:23:09      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

Attribute VB_Name = "模块1"

作者:landv开发时间:2015年12月28日18:09:34主要功能,为东风路小厨生成农行点餐宝所支持批量导入的格式。复制H行到TXT文本修改成UTF_8格式即可。

Function pinyin(p As String) As String
 
i = Asc(p)
 
Select Case i
 
Case -20319 To -20284: pinyin = "A"
 
Case -20283 To -19776: pinyin = "B"
 
Case -19775 To -19219: pinyin = "C"
 
Case -19218 To -18711: pinyin = "D"
 
Case -18710 To -18527: pinyin = "E"
 
Case -18526 To -18240: pinyin = "F"
 
Case -18239 To -17923: pinyin = "G"
 
Case -17922 To -17418: pinyin = "H"
 
Case -17417 To -16475: pinyin = "J"
 
Case -16474 To -16213: pinyin = "K"
 
Case -16212 To -15641: pinyin = "L"
 
Case -15640 To -15166: pinyin = "M"
 
Case -15165 To -14923: pinyin = "N"
 
Case -14922 To -14915: pinyin = "O"
 
Case -14914 To -14631: pinyin = "P"
 
Case -14630 To -14150: pinyin = "Q"
 
Case -14149 To -14091: pinyin = "R"
 
Case -14090 To -13319: pinyin = "S"
 
Case -13318 To -12839: pinyin = "T"
 
Case -12838 To -12557: pinyin = "W"
 
Case -12556 To -11848: pinyin = "X"
 
Case -11847 To -11056: pinyin = "Y"
 
Case -11055 To -2050: pinyin = "Z"
 
Case Else: pinyin = p
 
End Select
 
End Function
 
Function getpy(str)
 
For i = 1 To Len(str)
 
getpy = getpy & pinyin(Mid(str, i, 1))
 
Next i
 
End Function


Sub landv()

删除无用
    Rows("1:1").Select
    Selection.Delete Shift:=xlUp
    Rows("1:1").Select
    Selection.Delete Shift:=xlUp
  Columns("E:H").Select
    Selection.Delete Shift:=xlToLeft
    Columns("G:K").Select
    Selection.Delete Shift:=xlToLeft
剪切类别到第一行
 Columns("E:F").Select
    Selection.Cut
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight
删除格式
Cells.Select
    Selection.ClearFormats
删除B2
 Columns("B:B").Select
    Selection.Delete Shift:=xlToLeft

批量替换成类别编码,没有用循环,直接暴力一点吧。
 Columns("A:B").Select
ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="小厨", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="白酒", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="本地", Replacement:="2", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="茶水", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="果盘", Replacement:="1", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="果汁", Replacement:="9", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="红酒", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="花雕酒", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="火锅锅底", Replacement:="10", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="火锅肉类", Replacement:="11", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="火锅蔬菜", Replacement:="12", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="火锅小料", Replacement:="10", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="凉菜", Replacement:="1", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="面点", Replacement:="8", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="啤酒", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="破损", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="商品", Replacement:="4", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="四大罩", Replacement:="7", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="香烟", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="烤鱼", Replacement:="5", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="伴侣", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
         ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="热菜", Replacement:="2", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="烧烤", Replacement:="5", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="铁板", Replacement:="6", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="蒸炖", Replacement:="6", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="雅间费", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        ActiveCell.Columns("A:B").EntireColumn.Select
    Selection.Replace What:="饮料", Replacement:="3", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

品相名称转换成拼音
Columns("D:D").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("D1").Select
    ActiveCell.FormulaR1C1 = "=getpy(RC[-1])"
    Range("D1").Select
    Selection.AutoFill Destination:=Range("D1:D395")
    Range("D1:D395").Select
插入管道符
Range("G1").Select
    ActiveCell.FormulaR1C1 = "|"
    Range("G1").Select
    Selection.AutoFill Destination:=Range("G1:G395")
    Range("G1:G395").Select
生成最终格式
 Range("H1").Select
    ActiveCell.FormulaR1C1 = _
        "=RC[-7]&RC[-1]&RC[-6]&RC[-1]&RC[-5]&RC[-1]&RC[-4]&RC[-1]&RC[-3]&RC[-1]&RC[-2]"
    Range("H1").Select
    Selection.AutoFill Destination:=Range("H1:H395")
    Range("H1:H395").Select


End Sub

 

excel_VB宏脚本_批量生成点餐宝接受的格式

标签:

原文地址:http://www.cnblogs.com/landv/p/5083399.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!