我正在尝试制作能够做两件事的功能:
1.加入2个单元格的字符串 2.格式化部分
我已准备好每一个 - 如何在一个功能中制作? 代码为第一:
Function AA_Join2(str1 As String, str2 As String) As String
AA_Join2 = str1 & Chr(10) & Chr(10) & str2
End Function
和第二部分代码:
With ActiveCell.Characters(13, 15).Font
.Name = "Code EAN13"
.Size = 48
End With
如何在一个功能中完成它。 Sub不是一个选项,因为我必须为许多单元格制作它。如果有第一个函数的结果,第二部分适用于单元格文本,但不执行任何操作。
提前谢谢。
宏,它正在工作,我试图转换为公式是这样的:
Sub FontChange()
Dim strOne As String
Dim strTwo As String
Dim rngDest As Range
strOne = Worksheets("Sheet1").Range("A1").Value
strTwo = Worksheets("Sheet1").Range("B1").Value
Set rngDest = Range("D1")
Dim strBoth As String
Dim lonStrLen As Long
strBoth = strOne & Chr(10) & Chr(10) & strTwo
lonStrLen = Len(strBoth)
rngDest.Value = strBoth
With rngDest.Characters((lonStrLen - 14), 15).Font
.Name = "Code EAN13"
.Size = 48
End With
End Sub
经过几个小时的工作,我想出了宏观的最初想法。我不是张贴作为答案,仅供那些对解决方案感兴趣的人参考:
Sub AA_Join_Then_Format()
Dim strOneCol As String 'column where STRING ONE is located
Dim strTwoCol As String 'column where STRING TWO is located
Dim strBothCol As String 'column where both strings are joined
Dim lonCodeRow As Long 'current code row to be processed
Dim lonLastCodeRow As Long 'last row in use where picture names are
Dim strOne As String '
Dim strTwo As String '
Dim strBoth As String '
Dim lonStrLen As Long '
strOneCol = "A"
strTwoCol = "B"
strBothCol = "C"
lonCodeRow = 1
lonLastCodeRow = Cells(Rows.Count, strOneCol).End(xlUp).Row
Application.ScreenUpdating = False
Do While (lonCodeRow <= lonLastCodeRow)
strOne = Cells(lonCodeRow, strOneCol).Value
strTwo = Cells(lonCodeRow, strTwoCol).Value
strBoth = strOne & Chr(10) & Chr(10) & strTwo
lonStrLen = Len(strBoth)
Cells(lonCodeRow, strBothCol).Select
ActiveCell.Value = strBoth
With ActiveCell.Characters((lonStrLen - 14), 15).Font
.Name = "Code EAN13"
.Size = 48
End With
lonCodeRow = lonCodeRow + 1
Loop
Application.ScreenUpdating = True
End Sub