프로그래밍에 익숙하지는 않지만 Excel에서 매크로를 사용하는 것이 처음입니다. 나는 다음과 같은 매크로를 실행하려고, 엑셀 2010을 사용하고 있습니다 :셀 선택에서 매크로를 실행하려면 어떻게해야합니까?
Sub HideUnhideCells(ByVal Target As Range)
Dim keyCell As Range
Set keyCell = Range("C9")
Dim Cells1 As Range
Dim Cells2 As Range
'Call the function on C9 cell change
If Target.Address = "$C$9" Then
'Make Data Source available for for DRG and UCR
If keyCell.Value = "DRG" Or keyCell.Value = "UCR" Then
Set Cells1 = Range("C33")
Cells1.EntireRow.Hidden = False
Else
Set Cells1 = Range("C33")
Cells1.EntireRow.Hidden = True
End If
'Make MSA special cells available if MSA is selected
If keyCell.Value = "MSA" Then
Set Cells1 = Range("B34:C35")
Cells1.EntireRow.Hidden = False
Else
Set Cells1 = Range("B34:C35")
Cells1.EntireRow.Hidden = True
End If
'Make UCR cells available if UCR is selected
If keyCell.Value = "UCR" Then
Set Cells1 = Range("B36:C39")
Cells1.EntireRow.Hidden = False
Else
Set Cells1 = Range("B36:C39")
Cells1.EntireRow.Hidden = True
End If
'Remove extra name cells for 1-file and 2-file values
If keyCell.Value = "DRG" Or keyCell.Value = "ICD-9" Or keyCell.Value = "NCCI_Edits" Or keyCell.Value = "UB04" Then
Set Cells1 = Range("B21:C25")
Set Cells2 = Range("B28:C32")
Cells1.EntireRow.Hidden = True
Cells2.EntireRow.Hidden = True
ElseIf keyCell.Value = "ICD-10" Or keyCell.Value = "NDC" Then
Set Cells1 = Range("B22:C25")
Set Cells2 = Range("B29:C32")
Cells1.EntireRow.Hidden = True
Cells2.EntireRow.Hidden = True
Else
Set Cells1 = Range("B21:C25")
Set Cells2 = Range("B28:C32")
Cells1.EntireRow.Hidden = False
Cells2.EntireRow.Hidden = False
End If
End If
End Sub
내가 얘기 몇 게시물 및 자습서를 보았다,하지만이 작동하지 않습니다 왜 이해할 수 없다. 셀 C9는 드롭 다운 목록이며이 매크로를 실행하여 셀이 목록에 선택된 항목을 기반으로 표시되거나 표시되지 않도록합니다. 그러나 매개 변수를 지정하면 (위의 그림과 같이) UI에서 실행할 수 없으며 매개 변수를 지정하지 않으면 수동으로 만 실행할 수 있으므로 많은 도움이되지 않습니다.
지금 당장 C9 드롭 다운 목록에서 무언가를 선택하면 아무 일도 일어나지 않습니다. 아무도 내가 왜 알아낼 수 있습니까?
'교차하지 않는 경우 (target, range ("C9"))와 무관 한 경우'Worksheet_Change' 이벤트 사용 ' –
'Worksheet_Change' 이벤트 매크로를 사용하십시오. 이것들은 모듈 시트 시트가 아니라 워크 시트의 코드 시트에 들어갑니다. (워크 시트의 이름 탭을 마우스 오른쪽 단추로 클릭하고 워크 시트 코드 시트에 * 코드보기 *를 선택하십시오. – Jeeped
감사합니다. Siddharth Rout와 Jeeped! 워크 시트의 코드 시트에 대해 알지 못했거나 Worksheet_Change가 특정 이벤트였습니다. 우리는 승자를 얻었습니다! 여러분 중 한 명은 대답으로 답하고이 질문을 대답으로 표시 할 수 있습니까? 감사합니다! – FeelsLikeANewb