如果数字为浅蓝色,我想将名称(列A是名称)的值提取到另一张表。
到目前为止,我有一个提取数值的工作公式。我只是在将数字和名称提取到另一张纸上时遇到问题,这是我列出的第二个公式。我还想了解每行代码的作用。 感谢您的帮助,感激不尽
Function GetColorNum(prange As Range) As Double
Dim xOut As Double
Dim i As Long
For i = 1 To 100
If prange.Cells.Font.ColorIndex = 33 Then
xOut = prange.Value
End If
Next
GetColorNum = xOut
End Function
Sub tickerextract()
Dim c As Range
Dim ticker As String
If GetColorNum = True Then
Cells(i, 1).EntireRow.Copy
c.offset(0, 1) = ticker
Next c
End Sub
答案 0 :(得分:0)
尝试此操作(源范围和任意目标范围的任意开始列):
If prange.Cells.Font.ColorIndex=33 Then
Sheets("NAME").Cells(blah, 1).Copy Sheets("NAME2").Cells(moo, rawr)
End If
你会想要在你的循环中这样,以便每个值在迭代单元格时复制/粘贴,如果为真。
答案 1 :(得分:0)
如果我理解正确,它比最初写的更简单。
Option Explicit
Sub TickerExtract()
Dim rngTicker As Range
Set rngTicker = Worksheets("Tickers").Range("B1:B100") 'change as needed, assumes value in column B
Dim rngCel As Range
For Each rngCel In rngTicker
If rngCel.Font.ColorIndex = 33 Then
'change name as needed and column references
Worksheets("Other").Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(1, 2).Value = Array(rngCel.Offset(, -1).Value, rngCel.Value)
End If
Next
End Sub