Excel 内部单元格颜色似乎模糊了文本

Excel 内部单元格颜色似乎模糊了文本,excel,vba,string,Excel,Vba,String,我有一个问题,我的脚本无法“看到”单元格中的文本,如果它是彩色的 我有两行数据几乎相同,但其中只有一行是正确的,并且该单元格的内部colorindex=6 我想复制黄色单元格中的文本,并将其粘贴到D列中 我以为这会很简单。。。我错了,因为如果单元格是彩色的,我的脚本似乎看不到文本 我的问题集中在strOldFolderName和strNewFolderName上 我尝试将第2列和第3列中的文本输入这些字符串,但如果单元格为彩色,则字符串为空,即使=另一侧的值显示正确的文本,如果我在子单元格中设置

我有一个问题,我的脚本无法“看到”单元格中的文本,如果它是彩色的

我有两行数据几乎相同,但其中只有一行是正确的,并且该单元格的内部colorindex=6

我想复制黄色单元格中的文本,并将其粘贴到D列中

我以为这会很简单。。。我错了,因为如果单元格是彩色的,我的脚本似乎看不到文本

我的问题集中在strOldFolderName和strNewFolderName上

我尝试将第2列和第3列中的文本输入这些字符串,但如果单元格为彩色,则字符串为空,即使=另一侧的值显示正确的文本,如果我在子单元格中设置了一个停止并运行它

如果单元格未着色,则字符串没有问题,它包含正确的文本

但是,当我不知道是什么原因导致无法阅读单元格中的文本时,仅仅切换两者似乎不合逻辑

我希望这是有意义的。谢谢你的建议:)

以下是我的脚本:

 Sub PhotoDocCopyToLupus()
 
 Dim intOldFolderNameColumn As Integer 
 Dim intNewFolderNameColumn As Integer 
 Dim intCorrectFolderNameColumn As Integer 
 Dim intRowStart As Integer 
 Dim intRowEnd As Integer 
 Dim i As Integer
 
 Dim strOldFolderName As String 
 Dim strNewFolderName As String 
 Dim strCorrectFolderName As String
 
 intOldFolderNameColumn = 2 
 intNewFolderNameColumn = 3
 intCorrectFolderNameColumn = 4 
 intRowStart = 2 
 intRowEnd = 15
 
 Worksheets("Compare").Activate 
 Cells(1, 4) = "CorrectFolderName"
 
 For i = intRowStart To intRowEnd
 
     strOldFolderName = Trim(Cells(i, intOldFolderNameColumn))
     strNewFolderName = Trim(Cells(i, intNewFolderNameColumn))
 
         If Cells(i, intOldFolderNameColumn).Interior.ColorIndex = 6 Then
             strOldFolderName = Trim(Cells(i, intOldFolderNameColumn))
             strOldFolderName = strCorrectFolderName
         ElseIf Cells(i, intNewFolderNameColumn).Interior.ColorIndex = 6 Then
             strNewFolderName = Trim(Cells(i, intNewFolderNameColumn))
             strNewFolderName = strCorrectFolderName
         Else
             strCorrectFolderName = ""
             Cells(i, intCorrectFolderNameColumn).Interior.ColorIndex = 35
         End If
     
     Cells(i, intCorrectFolderNameColumn) = strCorrectFolderName
 
 Next i
 
 End Sub

你应该做你想做的事:

Sub-PhotoDocCopyToLupus()
'将常量用于固定值。。。
Const COL_OLD_FLDR的长度=2
Const COL\u NEW\u FLDR长度=3
Const COL_CORR_FLDR长度=4
Const ROW_开始时长=2
Const ROW_END长度=15
Dim i与字符串一样长,corrName与字符串一样长
使用工作表(“比较”)
.Cells(1,COL_CORR_FLDR)=“CorrectFolderName”
对于i=行\u开始到行\u结束
如果.Cells(i,COL\u OLD\u FLDR).Interior.ColorIndex=6,则
corrName=Trim(.Cells(i,COL\u OLD\u FLDR))
ElseIf.Cells(i,COL\u NEW\u FLDR).Interior.ColorIndex=6
corrName=Trim(.Cells(i,COL\u NEW\u FLDR))
其他的
corrName=“”
.Cells(i,COL_CORR_FLDR).Interior.ColorIndex=35
如果结束
.Cells(i,COL_CORR_FLDR)=corrName
接下来我
以
端接头

您是否尝试调试代码?使用F8一步一步地查看它的运行情况,并在每个步骤中检查变量值以找出问题所在。您的代码不会将strCorrectFolderName设置为空字符串以外的任何内容。它会:)非常感谢:)