gpt4 book ai didi

vba - 在 Excel 中取出字符并放入新列

转载 作者:行者123 更新时间:2023-12-04 21:15:54 25 4
gpt4 key购买 nike

嗨,我对 vba 有点陌生,所以我会尽可能地解释我的问题。
我在 Excel 中的 A 列中有一个数据集,我有很多这样的文件名:

 1. AB000**1234**45.tif 
2. AB000**1235**45.tif
3. AB000**1236**45.tif
4. AB000**1237**45.tif

ETC..

从此我想取出所有强字符并放入列 C所以它看起来像这样:
 1. 1234
2. 1235
3. 1236
4. 1237

ETC..

目前我有一个看起来像这样的代码:
Sub TakeOut
Dim str1 As String
Dim LR As Long
Dim cell As Range, RNG As Range

LR = Range("A" & Rows.Count).End(xlUp).Row
Set RNG = Range("A1:A" & LR)

For Each cell In RNG
L = Len(RNG)
If L > 0 Then
RNG = ...
End If
Next cell

Range("C:C").Columns.AutoFit

End Sub

我试图数左(5)和右(6),但不知道如何取出我想要的 4 个字符。
希望你能帮我解决这个问题。

最佳答案

如果要从字符串中取出强字符。在下面试试。它将把一个单元格中的所有粗体字符放在 C 列中。

希望你正在寻找这个?

Sub get_bold_content()
Dim lastrow, i, j, totlength As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lastrow
totlength = Len(Range("A" & i).Value)
For j = 1 To totlength
If Range("A" & i).Characters(j, 1).Font.Bold = True Then
outtext = outtext & Range("A" & i).Characters(j, 1).Text
End If
Next j
Range("C" & i).Value = outtext
outtext = ""
Next i
End Sub

enter image description here

关于vba - 在 Excel 中取出字符并放入新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38437272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com