macro doesn't work

Karat
NewLounger
Posts: 10
Joined: 19 Apr 2010, 22:48

macro doesn't work

Post by Karat »

Hi there
I've made a workbook for someone in Holland.. One of the macros I use is

Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
Application.ScreenUpdating = False
For i = 5 To 400
If Sheets("Outstanding").Range("E" & i).Value = "Yes" Then
Rows(i & ":" & i).EntireRow.Hidden = True
End If
Next i

Application.ScreenUpdating = True
End Sub

Works beautifully... but... it doesn't work on his computer. I phoned him and talked to him about enabling macros and all that and he does that, but still nothing happens.

Why wouldn't it work on a different machine?? Can it be a language issue ??

Thanks for any suggestions

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: macro doesn't work

Post by HansV »

Is "Outstanding" the name of the sheet this code is for?
Best wishes,
Hans

Karat
NewLounger
Posts: 10
Joined: 19 Apr 2010, 22:48

Re: macro doesn't work

Post by Karat »

Yes...

Karat
NewLounger
Posts: 10
Joined: 19 Apr 2010, 22:48

Re: macro doesn't work

Post by Karat »

Its most frustrating... I enter Yes and bingo all rows with Yes are hidden..
So I wondered if it was because he uses a Dutch version of Excel

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: macro doesn't work

Post by HansV »

With that, the code works OK on my Dutch PC, so I don't think it's a language issue.

Have you made sure that the user has enabled macros? If macro security is set to High (Excel 2003 or before), or if the workbook hasn't been stored in a trusted location (Excel 2007 or later), macros will be disabled.

By the way, your code will loop through all of the cells E5:E400 each time ANY cell on the worksheet is changed. The following version only processes the cells within the range E5:E400 that have actually been changed:

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
  Dim oCell As Range
  If Not Intersect(Range("E5:E400"), Target) Is Nothing Then
    Application.ScreenUpdating = False
    For Each oCell In Intersect(Range("E5:E400"), Target).Cells
      If oCell.Value = "Yes" Then
        oCell.EntireRow.Hidden = True
      End If
    Next oCell
    Application.ScreenUpdating = True
  End If
End Sub
Best wishes,
Hans

Karat
NewLounger
Posts: 10
Joined: 19 Apr 2010, 22:48

Re: macro doesn't work

Post by Karat »

Well he says he has enabled the macros. I have just emailed him with screendumps of the settings in options and the updated macro.
Will keep you posted. Thanks for your help