从某个系统导出数十万条数据,存在Excel表中,其中有个“与户主关系”字段,其值是一些数字代码,系统编制文档中说该字段是根据GBT 4761-2008 来编码的。数据用户想要把这些代码转换成对应的“家庭关系”,如代码02对应的 家庭关系是户主,用Excel中的替换功能来实施,由于其它字段的数据中也可能包含相同代码的内容,不是很方便。于是用宏VBA实现。
Sub replaceRelationWithOwner() ' 替换与户主关系 '数字在E列,从2行开始,Excel表格最大行数据是1048576 Range("E2:E1048576").Replace "01", "本人" Range("E2:E1048576").Replace "02", "户主" Range("E2:E1048576").Replace "10", "配偶" Range("E2:E1048576").Replace "11", "夫" Range("E2:E1048576").Replace "12", "妻" Range("E2:E1048576").Replace "20", "子" Range("E2:E1048576").Replace "21", "独生子" Range("E2:E1048576").Replace "22", "长子" Range("E2:E1048576").Replace "23", "次子" Range("E2:E1048576").Replace "24", "三子" Range("E2:E1048576").Replace "25", "四子" Range("E2:E1048576").Replace "26", "五子" Range("E2:E1048576").Replace "27", "养子或继子" Range("E2:E1048576").Replace "28", "女婿" Range("E2:E1048576").Replace "29", "其他儿子" Range("E2:E1048576").Replace "30", "女" Range("E2:E1048576").Replace "31", "独生女" Range("E2:E1048576").Replace "32", "长女" Range("E2:E1048576").Replace "33", "次女" Range("E2:E1048576").Replace "34", "三女" Range("E2:E1048576").Replace "35", "四女" Range("E2:E1048576").Replace "36", "五女" Range("E2:E1048576").Replace "37", "养女或继女" Range("E2:E1048576").Replace "38", "儿媳" Range("E2:E1048576").Replace "39", "其他女儿" Range("E2:E1048576").Replace "40", "孙子、孙女或外孙子、外孙女" Range("E2:E1048576").Replace "41", "孙子" Range("E2:E1048576").Replace "42", "孙女" Range("E2:E1048576").Replace "43", "外孙子" Range("E2:E1048576").Replace "44", "外孙女" Range("E2:E1048576").Replace "45", "孙媳妇或外孙媳妇" Range("E2:E1048576").Replace "46", "孙女婿外孙女婿" Range("E2:E1048576").Replace "47", "曾孙子或曾外孙子" Range("E2:E1048576").Replace "48", "曾孙女或曾外孙女" Range("E2:E1048576").Replace "49", "其他孙子、孙女或外孙子、外孙女" Range("E2:E1048576").Replace "50", "父母" Range("E2:E1048576").Replace "51", "父亲" Range("E2:E1048576").Replace "52", "母亲" Range("E2:E1048576").Replace "53", "公公" Range("E2:E1048576").Replace "54", "婆婆" Range("E2:E1048576").Replace "55", "岳父" Range("E2:E1048576").Replace "56", "岳母" Range("E2:E1048576").Replace "57", "继父或养父" Range("E2:E1048576").Replace "58", "继母或养母" Range("E2:E1048576").Replace "59", "其他父母关系" Range("E2:E1048576").Replace "60", "祖父母或外祖父母" Range("E2:E1048576").Replace "61", "祖父" Range("E2:E1048576").Replace "62", "祖母" Range("E2:E1048576").Replace "63", "外祖父" Range("E2:E1048576").Replace "64", "外祖母" Range("E2:E1048576").Replace "65", "配偶的祖父母或外祖父母" Range("E2:E1048576").Replace "66", "曾祖父" Range("E2:E1048576").Replace "67", "曾祖母" Range("E2:E1048576").Replace "68", "配偶的曾祖父母或外曾祖父母" Range("E2:E1048576").Replace "69", "其他祖父母或外祖父母关系" Range("E2:E1048576").Replace "70", "兄弟姐妹" Range("E2:E1048576").Replace "71", "兄" Range("E2:E1048576").Replace "72", "嫂" Range("E2:E1048576").Replace "73", "弟" Range("E2:E1048576").Replace "74", "弟媳" Range("E2:E1048576").Replace "75", "姐姐" Range("E2:E1048576").Replace "76", "姐夫" Range("E2:E1048576").Replace "77", "妹妹" Range("E2:E1048576").Replace "78", "妹夫" Range("E2:E1048576").Replace "79", "其他兄弟姐妹" Range("E2:E1048576").Replace "80", "其他" Range("E2:E1048576").Replace "81", "伯父" Range("E2:E1048576").Replace "82", "伯母" Range("E2:E1048576").Replace "83", "叔父" Range("E2:E1048576").Replace "84", "婶母" Range("E2:E1048576").Replace "85", "舅父" Range("E2:E1048576").Replace "86", "舅母" Range("E2:E1048576").Replace "87", "姨父" Range("E2:E1048576").Replace "88", "姨母" Range("E2:E1048576").Replace "89", "姑父" Range("E2:E1048576").Replace "90", "姑母" Range("E2:E1048576").Replace "91", "堂兄弟、堂姐妹" Range("E2:E1048576").Replace "92", "表兄弟、表姐妹" Range("E2:E1048576").Replace "93", "侄子" Range("E2:E1048576").Replace "94", "侄女" Range("E2:E1048576").Replace "95", "外甥" Range("E2:E1048576").Replace "96", "外甥女" Range("E2:E1048576").Replace "97", "其他亲属" Range("E2:E1048576").Replace "99", "非亲属" End Sub