Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 1 Then If Target.Address = strAddress Then If TypeName(Target.Value) = "Double" Then If Target.Value <> dlbInput * 8 Then dlbInput = Target.Value Target.Value = Target.Value * 8 End If End If Else If TypeName(Target.Value) = "Double" Then strAddress = Target.Address dlbInput = Target.Value Target.Value = Target.Value * 8 End If End If End If End Sub
3으로 입력하면 24가 되도록하고 싶으시다고요?
왜 옆 셀에 수식을 사용해서 A1*8이라는 식으로 사용하지 않을까요?
2가지 해결 방법이 생각납니다.
1. 자동 고침을 사용하는 경우..
- 조건 : 8배로 변환되어야하는 숫자가 한정적일데.. 1부터 15까지라던가할 경우..
- 방법 : 엑셀 옵션 > 언어 교정 > 자동 고침 옵션에 3과 24를 등록.. 나머지 숫자들도 등록..
- 단점 : 전체 셀에 모두 적용됨. 3만 따로 입력하기 힘듬.. 항상 24로 바뀌니까..
==> 좀 구리네요.. 이 방법... 결국 VBA를 사용할 수 밖에.. ㅠㅠ
2. VBA를 사용하는 경우..
Worksheet_Change 이벤트를 사용하는 것인데요..
값을 8배로 증가시킬때마다 Worksheet_Change가 새로 발생해서 중복 계산되지 않게 하는게 귀찮네요..ㅋ
첨부파일을 참고하세요.. ^^
A열에 숫자를 입력할때만 8배로 증가시키도록 해놨습니다.
다운받기 : abyul.com_20120613_worksheetChangeEvent-2.xlsm
Option Explicit
Dim strAddress As String
Dim dlbInput As Double
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
If Target.Address = strAddress Then
If TypeName(Target.Value) = "Double" Then
If Target.Value <> dlbInput * 8 Then
dlbInput = Target.Value
Target.Value = Target.Value * 8
End If
End If
Else
If TypeName(Target.Value) = "Double" Then
strAddress = Target.Address
dlbInput = Target.Value
Target.Value = Target.Value * 8
End If
End If
End If
End Sub