我如何...获取细胞的值并放入一个细胞中加下划线的细胞 [英] How do i...get values of cell and put in one cell with underline for some of the cells
问题描述
你好Sir
你能不能帮我编写代码,为单元格中的一个或多个单词添加下划线..例如
in cell g1,h1,i1,j1,k1
i想要获取所有单元格的值并将其放入单元格 a1
,我想在cel h1
和单元格 j1 $ c下添加下划线$ c>
h1
和 j1
是一个数字格式如... 1,000,000
单元格值 g1,i1,k1
是单词
所以我怎样才能获得所有这些单元格值并将所有单元格放在一个单元格中 a1
,只有 h1 $ c $的下划线c>和
j1
i希望有人可以帮助我
感谢所有人
我尝试了什么:
我正试图获得细胞的价值(例如 G1,H1,I1
和 K1
)并将其放在一个带有下划线到单元格的单元格中 H1
和 J1
如下图所示:
hello Sir
would you please help me to write code to add underline to one or more of word inside a cell ..for example
in cell g1, h1, i1, j1, k1
i want to get the value of all that cells and put it in cell a1
and i want to add underline to the cel h1
and the cell j1
h1
and j1
are a number has format like ...1,000,000
value of cells g1, i1, k1
are words
so how can i get all this cells value and put all in one cell a1
with underline for only h1
and j1
i wish some one can help me
thanks for all
What I have tried:
i'm trying to get value of cells (for example G1, H1, I1
and K1
) and put it in one cell with underline to cell H1
and J1
like as showing bellow :
G1 H1 i1 J1 K1
word1 1,000,000 word2 2,000,000 word3
i想要使用Excel公式或Excel VBA获取结果如下所示
i want to use Excel Formula or Excel VBA to get the result as showing below
word1 1,000,000 word2 2,000,000 word3
withunderline为H1和J1
withunderline for H1 and J1
推荐答案
检查:
Check this:
Option Explicit 'force variable declaration
Sub JoinTextAndUnderline()
'variables
Dim wsh As Worksheet
Dim i As Integer, beg As Integer, lng As Integer
Dim sTmp As String
'initialize worksheet object
Set wsh = ThisWorkbook.Worksheets("Sheet1")
'set text to cell A1
wsh.Range("A1") = wsh.Range("G1") & " " & wsh.Range("H1") & " " & _
wsh.Range("I1") & " " & wsh.Range("J1") & " " & wsh.Range("K1")
'change formatting
'loop through the cells in column-range: (G:J)
For i = 0 To 4
sTmp = sTmp & wsh.Range("G1").Offset(ColumnOffset:=i) & " "
Select Case i
Case 1, 3
'get the beginning of text to underline
beg = Len(sTmp) - Len(wsh.Range("G1").Offset(ColumnOffset:=i).Text)
'get the length of text to underline
lng = Len(wsh.Range("G1").Offset(ColumnOffset:=i).Text)
'underline
wsh.Range("A1").Characters(beg, lng).Font.Underline = True
End Select
Next
'clean up!
Set wsh = Nothing
End Sub
祝你好运!
Good luck!
类似的东西:
Something like:
Range("H1").Select
Selection.Font.Underline = xlUnderlineStyleSingle
您始终可以找到示例代码通过使用Excel的宏记录功能。
You can always find sample code by using the Macro record feature of Excel.
谢谢你,但它不起作用
这篇关于我如何...获取细胞的值并放入一个细胞中加下划线的细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!