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

相关推荐
wtsolutions1 小时前
MCP Service Integration - Excel to JSON for AI and Automation
人工智能·json·excel
wtsolutions12 小时前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions13 小时前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
wtsolutions16 小时前
Using the JSON to Excel API - Programmatic Access for Developers
json·excel
qq_4351395716 小时前
EasyExcel(FastExcel)Excel导出功能 技术文档
excel
wtsolutions19 小时前
Understanding JSON Formats - What JSON to Excel Supports
json·excel
wtsolutions20 小时前
Advanced Features - Unlocking the Power of JSON to Excel Pro
linux·json·excel
fs哆哆21 小时前
VB.NET和VBA教程-如何查找Excel数据区域边界
excel
小矮强21 小时前
Excel中根据年月日提取月日,并按月日进行排序
excel
开开心心_Every1 天前
图片批量压缩工具:支持有损无损两种模式
python·游戏·微信·django·pdf·excel·语音识别