indi visual
Member
'Having trouble hiding the entire active column (based on these 4 criterias)
[pre]<br />
'// HIDE COLUMN IF...<br />
'' 1 if that column is not after column X<br />
'' 2 if that column is not before column E<br />
'' 3 if that column has any value<br />
'' 4 if that column is the last active column in range<br />
<br />
Private Sub Worksheet_SelectionChange(ByVal Target As Range)</p>
<p>Dim myRange As Range<br />
Dim lastActiveColumn As Range</p>
<p>Set myRange = Range("A1:Z100"
<br />
Set lastActiveColumn = myRange.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)</p>
<p>If Target.Column <= 25 Then<br />
If Target.Column >= 5 Then<br />
If Application.CountIf(Target.Column, "*"
> 0 Then<br />
If Target.Column = lastActiveColumn Then<br />
Target.EntireColumn.Hidden = True<br />
End If<br />
End If<br />
End If<br />
End If</p>
<p>End Sub<br />
[/pre]
[pre]<br />
'// HIDE COLUMN IF...<br />
'' 1 if that column is not after column X<br />
'' 2 if that column is not before column E<br />
'' 3 if that column has any value<br />
'' 4 if that column is the last active column in range<br />
<br />
Private Sub Worksheet_SelectionChange(ByVal Target As Range)</p>
<p>Dim myRange As Range<br />
Dim lastActiveColumn As Range</p>
<p>Set myRange = Range("A1:Z100"
Set lastActiveColumn = myRange.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious)</p>
<p>If Target.Column <= 25 Then<br />
If Target.Column >= 5 Then<br />
If Application.CountIf(Target.Column, "*"
If Target.Column = lastActiveColumn Then<br />
Target.EntireColumn.Hidden = True<br />
End If<br />
End If<br />
End If<br />
End If</p>
<p>End Sub<br />
[/pre]