Computing.Net > Forums > Office Software > Excel Macro

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel Macro

Reply to Message Icon

Name: toast (by NoIdea)
Date: June 16, 2008 at 12:36:15 Pacific
OS: XP Pro
CPU/Ram: 2.3Ghtz / 1gig
Product: EMachines 580
Comment:

I want to use the following command
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("A51,A100,A149")).
But instead of a target range A51,A100,A149 I want to put the command in each of the cells and perform the function associated with the particular cell. However I do not seem to be able to put this function into the workbook 3 times as the name ambiguous error is flagged because I am using the same name, if I append the title the function does not work.
I also need to know how to register variables as Rw and returnvalue are not able to be used.
This is an example of what I want to do

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("A51")) Is Nothing Then
If Target.Value > 0 Then
.Unprotect
Application.ScreenUpdating = False
For Rw = 51 To 99
Cells(Rw, 1).EntireRow.Hidden = False
Next
Application.ScreenUpdating = True
.Protect
End With
End Sub

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("A100")) Is Nothing Then
If Target.Value > 0 Then
.Unprotect
Application.ScreenUpdating = False
For Rw = 100 To 148
Cells(Rw, 1).EntireRow.Hidden = False
Next
Application.ScreenUpdating = True
.Protect
End With
End Sub



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: June 16, 2008 at 14:47:01 Pacific
Reply:

First off, let's clear up the terminology.

What you are doing is not called a Command or a Function. It's called a Worksheet Change macro.

OK, now onto your problems...

It looks like you are trying to perform an action based on certain target cells, specifically A51,A100,A149.

Instead of

If Not Application.Intersect(Target, Range("A100")) Is Nothing

try:


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$A$51" Then
'Your A51 code goes here
End If

If Target.Address = "$A$100" Then
'Your A100 code goes here
End If

If Target.Address = "$A$149" Then
'Your A149 code goes here
End If

End Sub


I'm not sure what you mean when you say "Rw and returnvalue are not able to be used."

What error do you get?

The only thing I can think of based on the limited information provided is that you have Option Explicit set someplace which would force you to declare all variables with a Dim statement before you can use them.

Give us some more details and we'll see what we can do.


0

Response Number 2
Name: toast (by NoIdea)
Date: June 17, 2008 at 06:37:12 Pacific
Reply:

You were quite right Option Explicit was there. Something else you've taught me.
The Worksheet_Change(ByVal Target As Range)also works for me.
Thank you very much for all your help excellent advice as always.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Excel Macro

Run Excel Macro as Automated Task on Server www.computing.net/answers/office/run-excel-macro-as-automated-task-on-server/9661.html

Excel Macro read and process CSV www.computing.net/answers/office/excel-macro-read-and-process-csv/3820.html

Excel macro www.computing.net/answers/office/excel-macro/4051.html