PDA

View Full Version : [SOLVED:] worksheet_change to select a range



scorpid18
11-18-2015, 04:18 AM
Hi there! I've got a problem with worksheet_change :crying:
The purpose of my macro is, if the target is $C$5 at sheet("unit performance"), then the macro should select range("C5:E5") (a merged cell) in another worksheet, but the macro keep on refusing to do so. What is the problem?

here's the code I've made :


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$C$5" Then

Sheets("RM performance").Activate
Range("C5:E5").Select 'this is where the macro stuck (run time error '1004' - select method of range class failed)

any suggestion will be appreciated. Sorry for my bad english also. Thanks before :hi:

Ringhal
11-18-2015, 04:49 AM
You need to specify the worksheet you're referring to:

Sheets("RM performance").Activate
Sheets("RM performance").Range("C5:E5").Select

or simply :

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$C$5" Then

Sheets("RM performance").Range("C5:E5").Select
End If
End Sub

Aflatoon
11-18-2015, 05:29 AM
The latter won't work because you need to activate that sheet first.

scorpid18
11-18-2015, 08:59 AM
That's it !!! didn't know I have to put the sheets too...Thanks a lot..my macro works perfectly now !