使用VBA将单元格格式从一张纸映射到另一张纸

时间:2018-08-27 13:22:59

标签: excel vba

所以我递归地将一些文本写到表格上。在另一张工作表中,我将所有这些文本值放在另一张工作表的列中,其中右列包含我拥有的文本值的相应重命名和格式。这是一个例子: https://ethercalc.org/46ky7t3kbik1

如何引用此“格式设置”工作表,以获取可以映射到的每个单元格右侧的单元格的值和格式?

1 个答案:

答案 0 :(得分:1)

因此不确定递归部分,但这是引用sheets/cells并搜索粗体彩色的单词的方法。

Function returnFontColor(targetString As String) As Integer

    Dim formatSheet As Worksheet
    Dim lastRow As Long
    Dim row As Long
    Dim counter As Integer

    returnFontColor = 0

    Set formatSheet = ThisWorkbook.Worksheets("insert format sheet name")

    With formatSheet

        lastRow = .Cells(.Rows.Count, 2).End(xlUp).Row

        For row = 2 To lastRow
            If Lcase(CStr(.Range("B" & row).Value)) = Lcase(CStr(targetString)) Then
                For counter = 1 To Len(.Range("C" & row).Value)
                    If .Range("C" & row).Characters(Start:=counter, Length:=1).Font.ColorIndex <> 0 Then

                        returnFontColor = .Range("C" & row).Characters(Start:=counter, Length:=1).Font.ColorIndex
                        GoTo Exiter
                    End If
                Next
            End If
        Next
    End With
Exiter:

End Function