如何制作一个宏来替换 Excel 中的字符串

How to make a macro that replace string in Excel

有谁知道如何在 Excel 中制作一个转换字符串的宏? 我想根据此转换转换一列中存在的所有字符串:

initial result of macro
first_name $firstName
last_name $lastName
email $email
email2 $email2

如果是字符,我想在下划线后转换成大写。

非常感谢!

记事本++解决方案:

  • Ctrl+H
  • 查找内容:(?:^([^\W_]+)|\G(?!^))(?:_([^\W_]*))?
  • 替换为:(?1$)\u
  • 检查 环绕
  • 检查 正则表达式
  • 全部替换

解释:

(?:             # non capture group
    ^               # beginning of line
    (               # group 1
        [^\W_]+         # 1 or more non non-word character or underscore
    )               # end group 1
  |               # OR
    \G(?!^)         # restart from last match position, not at the beginning of lie
)               # end grroup
(?:             # non capture group
    _               # underscore
    (               # group 2
        [^\W_]*         # 0 or more non non-word character or underscore
    )               # end group 1
)               # end group

替换:

(?1             # if group 1 exists
    $            # add a dollar before the group 1
)               # endif
\u            # uppercase the first letter of group 2

截图(之前):

截图(后):