如何使用VBA合并多个单元格 [英] How to merge several cells using VBA
本文介绍了如何使用VBA合并多个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在excel和VBA方面存在一些问题,因为他们不了解很多知识.我从pdf复制了文本,这很糟糕.我的单元格包含一些文本.问题在于,一个段落中的文本在多个单元格中被细分了.每个段落的开头都有一个粗体字(例如 CLR.),它描述了文本的其余部分.因此,它定义了每个段落应从何处开始.我如何将这些单元合并成一个单元?
I have some problems with excel and VBA, in that don't know have much knowledge. I copied text from pdf and it's awful. I have cells which contain some text. The problem is that the text from one paragraph is broken down over several cells. At the beginning of each paragraph is a word in bold (e.g. CLR.) which describes the rest of the text. As such, it defines where each paragraph should start. How I can merge these cells into one?
我看到了
我要
推荐答案
Sub MergeText()
Dim strMerged$, r&, j&, i&
r = 1
Do While True
If Cells(r, 1).Characters(1, 1).Font.Bold Then
strMerged = "": strMerged = Cells(r, 1)
r = r + 1
While (Not Cells(r, 1).Characters(1).Font.Bold) And Len(Cells(r, 1)) > 0
strMerged = strMerged & Cells(r, 1)
r = r + 1
Wend
i = i + 1: Cells(i, 2) = strMerged
Cells(i, 2).Characters(1, InStr(1, strMerged, ".", vbTextCompare)).Font.Bold = True
Else
Exit Do
End If
Loop
End Sub
这篇关于如何使用VBA合并多个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文