엑셀 매크로 -색상표 만드기
엑셀을 사용해서 색상표를 추출하는 매크로 입니다 .
사무실에서 필요해서 간단하게 만들었습니다.
Sub colorTest()
' 기본값 세팅
Cells(1, 2) = "Red"
Cells(2, 2) = "Green"
Cells(3, 2) = "Blue"
Cells(1, 4) = "RGB 값"
Cells(1, 5) = "색상"
' 소수점 이하는 반올림
rVal = Round(Cells(1, 3), 0)
gVal = Round(Cells(2, 3), 0)
bVal = Round(Cells(3, 3), 0)
'반올림한 값을 다시 적어줌
Cells(1, 3) = rVal
Cells(2, 3) = gVal
Cells(3, 3) = bVal
Range(Cells(4, 1), Cells(4, 3)).Merge
Cells(4, 1) = "* 소수점 이하 값은 반올림됩니다."
Range(Cells(2, 4), Cells(256, 6)).Clear
i = 1
Do While i < 256
nrVal = i * rVal
If i * rVal > 255 Then
nrVal = 255
End If
ngVal = i * gVal
If i * gVal > 255 Then
ngVal = 255
End If
nbVal = i * bVal
If i * bVal > 255 Then
nbVal = 255
End If
'값을 실제로 부여함.
Cells(i + 1, 4) = nrVal & ", " & ngVal & ", " & nbVal
Cells(i + 1, 5).Interior.Color = RGB(nrVal, ngVal, nbVal)
'조건이 맞으면 작업 중지
If (nrVal = 255 And ngVal = 255 And nbVal = 255) Then
i = 256
Else
i = i + 1
End If
Loop
Cells(5, 4).Select
ActiveWindow.FreezePanes = True
End Sub