2016-09-22 8 views
-1

그래서 나는 다음과 같은 VBA 코드가 있습니다VBA : 색의 셀 값이 따라 잡아

Function CountCcolor(range_data As Range, criteria As Range) As Long 

Dim datax As Range 
Dim xcolor As Long 

xcolor = criteria.Interior.ColorIndex 

For Each datax In range_data 
    If datax.Interior.ColorIndex = xcolor Then 
     CountCcolor = datax.Select 
    End If 
Next datax 

End Function 

이 코드는 특정 배경 색상의 범위 주어진 andsearches을 통해 루프를. 그런 다음 해당 색상의 값을 가져 와서 선택한 셀에 배치합니다.

올바른 배경색의 데이터가 숫자가 아닌 텍스트 인 경우 내 문제가 발생합니다.

왜 셀에서 텍스트를 가져올 수 없는지에 대한 아이디어가 있습니까?

그냥 # VALUE! 만약 그 순간에 텍스트.

+0

예를 몰래 들어 @Shai 왜 그래에

Function CountCcolor(range_data As Range, criteria As Range) As String Dim datax As Range Dim xcolor As Long xcolor = criteria.Interior.ColorIndex For Each datax In range_data If datax.Interior.ColorIndex = xcolor Then CountCcolor = datax.Select End If Next datax End Function 

감사해야합니다, 당신은 Long'로'기능 CountCcolor을 정의, 그래서 그것은 단지 숫자에 동의합니다. –

+0

나는 또한 datax.Text를 시도했다. 그러나 행운이 없다. – Silk13

+0

당신은'CountCcolor '가'Long'으로 정의 되어질 수 없다. –

답변

0
CountCcolor is defined as Long 

코드