Excel 宏录制与VBA编程 —— 12、文本字符串类型相关(转换、拆分、分割、连接、替换、查找、“Like“)

字符串分割,文末示例(文末代码3附有源码)

 

 

代码1 - 基础字符串

 

代码2 - 字符串拆分

 

代码3 - 字符串分割
cpp 复制代码
Option Explicit

Sub WorkbooksClear()
    Dim DataRange As Range
    Set DataRange = Range("C2:E12")
    DataRange.Clear
End Sub

Sub WorkbooksTest()
    Dim DataRange As Range
    Set DataRange = Range("A2:A12")
    
    Dim DataRowCount As Long
    DataRowCount = DataRange.Rows.Count
    
    Dim Index As Integer
    For Index = 1 To DataRowCount
        Dim Item As Range
        Set Item = DataRange.Cells(Index, 1)
        
        Dim Items() As String
        Items = VBA.Split(Item, "-")
        
        Dim StringIndex As Integer
        For StringIndex = LBound(Items) To UBound(Items)
            Item.Offset(0, StringIndex + 2).Value = Items(StringIndex)
        Next StringIndex
    Next Index
End Sub

 

代码4 - 字符串连接

 

代码5 - 字符串替换

 

代码6 - 字符串比较、大小写转换

 

代码6 - 字符串查找

 

代码7 - "Like"正则

 

关注

笔者 - jxd

相关推荐
wuyk5551 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel
黎羽_2 天前
Excel 插图在手机端不显示/错位:完整排查手册
excel·openpyxl·移动端·办公文档
用户298698530143 天前
React 前端实现 Excel 与 CSV 互转:基于 WebAssembly 的浏览器端方案
javascript·react.js·excel
仓库日记4 天前
Excel进销存何时该换?用3项检查判断是否需要软件
经验分享·excel·进销存·开单软件
用户0332126663674 天前
如何使用 Python 将 JSON 转换为 Excel
python·excel
2601_967980115 天前
Python自动化办公:模块、库与样式调整教程
python·excel·自动化办公·openpyxl·样式调整
用户0332126663675 天前
使用 Python 轻松加密或解密 Excel 文档
python·excel
总裁余(余登武)7 天前
【python项目】:1操作EXCEl自动化开发
python·自动化·excel
ailitsoft9 天前
库存管理系统如何记录跨门店调拨后的收货差异?
excel·零售·软件需求
百事牛科技10 天前
Excel的三种密码:防看、防存、防乱改,各管各的
windows·excel