[엑셀 VBA #18] 엑셀 매크로로 서식 지정하기(테두리, 폰트, 글자크기 등)



이번 엑셀 매크로 강의에서는 엑셀 셀의 서식을 설정하는 방법에 대해 알아보겠습니다.


엑셀 매크로로 셀 테두리, 색깔, 폰트, 글자 크기 등 다양한 서식을 구성할 수 있습니다.


매크로 파일을 받고 따라와주세요.




셀 테두리 만들기

Cells(3, 3).Borders(xlEdgeLeft).LineStyle = xlContinuous    '셀의 왼쪽 테두리 설정

Cells(3, 3).Borders(xlEdgeRight).LineStyle = xlContinuous    '셀의 오른쪽 테두리 설정

Cells(3, 3).Borders(xlEdgeTop).LineStyle = xlContinuous    '셀의 위쪽 테두리 설정

Cells(3, 3).Borders(xlEdgeBottom).LineStyle = xlContinuous    '셀의 아래쪽 테두리 설정


위와 같이 테두리가 생성됩니다.

테두리의 모양을 바꾸고 싶다면 xlContinuous를 다른 값으로 바꿔주면 됩니다.


xlDashDotDot       


xlDash                 


xlSlantDashDot      


xlDouble              



테두리의 굵기를 바꾸고 싶다면 .weight 설정을 하면 됩니다.


Cells(3, 3).Borders(xlEdgeLeft).Weight = xlThin

Cells(3, 3).Borders(xlEdgeRight).Weight = xlThin

Cells(3, 3).Borders(xlEdgeTop).Weight = xlMedium

Cells(3, 3).Borders(xlEdgeBottom).Weight = xlThick






셀 색상 변경하기


Cells(4, 3).Interior.Color = vbRed




색상값은 vbRed, vbBlue등으로 설정할 수 있지만, 다양한 사용자 정의 색상은 RGB로 설정할 수 있습니다.


Cells(4, 3).Interior.Color = RGB(111, 222, 50)







문자 서식 지정하기


Cells(3, 4).Font.Size = 8        '폰트 크기(글자 크기) 설정 

Cells(4, 4).Font.Bold = True        '폰트 볼드체로 바꾸기 True/False

Cells(5, 4).Font.Name = "궁서체"    '폰트 바꾸기

Cells(6, 4).Font.Italic = True        '폰트 이탤릭체(기울임꼴) 바꾸기 True/False

Cells(7, 4).Font.Underline = True        '폰트에 밑줄 긋기 True/False








Posted by Simon K
: