excel - 如何切割子串?
问题描述
我有很多可以包含斜体字体的字符串。我想用这种字体复制这个字符串。在每个新字符串中,我都有粗体字
我试过:
Public Function GetDefinition(ByVal rngText As Range) As String
Dim theCell As Range
Set theCell = rngText.Cells(1, 1)
For I = 1 To Len(theCell.Value)
If theCell.Characters(I, 1).Font.Bold = False Then
If theCell.Characters(I + 1, 1).Text = " " Then
theChar = theCell.Characters(I, 1).Text
Else
theChar = theCell.Characters(I, 1).Text
End If
Results = Results & theChar
End If
Next I
GetDefinition = Results
End Function
解决方案
我认为你可以使用这个:
Option Explicit
Sub test()
Dim LastRow As Long, i As Long, j As Long, PositionOfDot As Long
With ThisWorkbook.Worksheets("Sheet1")
'Find last row of column A
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
'Loop from row 1 to lastrow
For i = 1 To LastRow
'Copy paste from column A to C keeping formatting
.Range("A" & i).Copy .Range("C" & i)
'Find the position of "."
PositionOfDot = InStr(1, .Range("A" & i), ".")
'Delete characters starting from the first one up to PositionOfDot+1
.Range("C" & i).Characters(1, PositionOfDot + 1).Delete
Next i
End With
End Sub
结果:
推荐阅读
- c# - 使用实际上是列表的类对象数组
- json - Terraform:如何通过 json 文件迭代地图输入的键值对
- reactjs - Redux 状态加载,但反应不渲染
- node.js - 在我的基于 NodeJS 的 lambda 中,无法在回调 getSignedUrl 时调用 AWS SES sendEmail 函数
- hibernate - 使用 AND/OR 组合的休眠条件
- java - 我的快速排序方法有一个基本案例,但我仍然收到堆栈溢出错误?
- node.js - 如何使用 Sequelize 在表(复合键)之间创建关联?
- sql - T-sql,运行名称存储在字符串变量中的函数......使用 exec 之类的东西......并捕获返回值
- php - 使用 natsort() 对函数的返回值进行排序
- computer-science - 每当通过汇编(RISC-V)在字符串中出现双辅音时,如何打印减号(-)?