What error do you get?
Your code works fine for me. I'd probably rearrange it a little:
Private Sub Worksheet_Change(ByVal Target As Range)
Const nMAX As Long = 10
Dim nRows As Long
Application.ScreenUpdating = False
With Me
With .Range("B8")
If Intersect(Target(1), .Cells) Is Nothing Then Exit Sub
nRows = .Value
End With
.Range(.Cells(1, 5), .Cells(1, _
.Columns.Count)).EntireColumn.Hidden = True
.Range(Cells(1, 5), .Cells(1, _
nRows * 2 + 6)).EntireColumn.Hidden = False
End With
With Sheets("Dataprocessing").Range("23:23")
.Resize(nMAX).EntireRow.Hidden = True
.Resize(nRows).EntireRow.Hidden = False
End With
With Sheets("List").Range("27:27")
.Resize(nMAX).EntireRow.Hidden = True
.Resize(nRows).EntireRow.Hidden = False
End With
End Sub
but that's mostly a matter of taste.
In article <(E-Mail Removed)>,
(E-Mail Removed) wrote:
> Now I have this in my code. Is this the correct way??
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> If Not Intersect(Target, Range("B8")) Is Nothing Then
> Application.ScreenUpdating = False
> Range(Cells(1, 5), _
> Cells(1, Columns.Count)).EntireColumn.Hidden = False
> Range(Cells(1, Range("B8").Value * 2 + 6), _
> Cells(1, Columns.Count)).EntireColumn.Hidden = True
> End If
>
> Const nMAX As Long = 10
> Dim nRows As Long
> nRows = Me.Range("B8").Value
> With Sheets("Dataprocessing").Range("23:23")
> .Resize(nMAX).EntireRow.Hidden = True
> .Resize(nRows).EntireRow.Hidden = False
> End With
> With Sheets("List").Range("27:27")
> .Resize(nMAX).EntireRow.Hidden = True
> .Resize(nRows).EntireRow.Hidden = False
> End With
> End Sub
>
> I don't think, cause I get an error.
> Can you make it right??