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

相关推荐
鲲穹AI种草9 小时前
Excel 表格批量处理与数据整理,多款表格工具能力客观记录
excel·表格处理
cspttty11 小时前
2026秋招供应链分析师技能栈:SQL、Excel、BI与业务分析
数据库·sql·excel
Zzq_Fighting1 天前
Excel批量匹配数据
excel
E_ICEBLUE1 天前
Python 实现 Excel 转 Markdown,支持工作表、单元格区域和批量处理
python·excel·markdown·格式转换
拆房老料1 天前
ONLYOFFICE 集群部署实战:9.3 多实例方案与 9.4 架构变化
开源·word·excel·开源软件·ppt
ms365copilot2 天前
Excel Copilot挖掘数据洞察,不用精通函数也能做数据分析 (1)
数据分析·excel·copilot
babe小鑫2 天前
精算学专业秋招:Excel、SQL、R和Python应该先练什么
sql·r语言·excel
医疗信息化王工2 天前
DataForge:基于 Python 的数据库批量导出 Excel 工具——从架构到部署的全流程实战
数据库·python·excel
1314lay_10072 天前
通过Sql Server创建EXCEL文件:master..xp_cmdshell
数据库·excel
2601_962300812 天前
Python + Requests + Pytest + Excel + Allure:接口自动化测试项目实战
python·excel·pytest·allure·requests