【发布时间】:2012-06-28 06:28:57
【问题描述】:
尝试遍历一系列单元格并根据另一个单元格中的文本值为它们分配标签。所以如果 Cell J2 = "This Text" Then Cell A2 = "This Label"
截至目前,我不断收到运行时错误编号 424,说明需要对象
Private Function getPhase(ByVal cell As Range) As String
Select Case cell.Text
Case "Text1"
getPhase = "Label1"
Case "Text2"
getPhase = "Label2"
End Select
End Function
Sub setPhase()
Dim cycle As Range
Dim phase As Range
Set cycle = Range("J2:J10")
Set phase = Range("A2:A10")
For Each cell In phase.Cells
phase.Text = getPhase(cycle)
Next cell
End Sub
【问题讨论】:
-
你试过
cell.value吗? -
错误出现在哪一行?
-
刚试了一下,"phase.Text = getPhase(cycle)"失败
-
您需要 VBA 吗?您也可以使用 Excel 公式解决此问题。