Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Syntax got me again

I have the following macro that is supposed to copy one of two areas
depedning upon whehter a certain worksheet cell, whihc is range-named,
is Yes or No. Something in the syntax or dimensioning must be wrong
since it always chooses the 2nd copy range (the else condition), never
the 1st range (the then condition). Perhaps it's how I'm dimensioning
it, perhaps how I am phrasing the if statement, or perhaps you can't
use an IF statement the way I do for just the beginning of a copy
command, or perhaps I need a go to statement.

I'm sure this is trivial to fix, sincw the error is really dumb.
Thanks much!

Please help! Here is my very short macro:

Sub SetUpModelAllocationOnSummarySheet()

Dim ModelsAlreadyBuiltYesNoIndicator As Variant



If ModelsAlreadyBuiltYesNoIndicator = "No" Then
Range("AH20:AH64").Select
Selection.Copy

Else
Range("AG20:AG64").Select
Selection.Copy
End If

Range("Z20:z64").Select

ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Syntax got me again

Hi DA,

Your first line of code only creates a variable with a strangs long
name.
At this point it has no value!
In yuor secod lie of code you are testing is the value equals "No".
Which it does not.
So the Else part of your code is executed.

You should asign a value to this variable toget the If part executed
Maybe something like:

ModelsAlreadyBuiltYesNoIndicator = Range("AH1").Value

HTH,

Wouter
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Syntax got me again

I see - it won't recognize the range name as it stands. Actually, I
only tried that becasue what I was sure would work, didn't.

My whole reason for using the range name was to make sure the macro
worked even if I insert rows or columns so your suggestion isn't quite
good enough (for me). However, somehow, your statement got me to go
back to my first attempt which was:

If Range("ModelsAlreadyBuiltYesNoIndicator").Value = "No" Then

and it works!

I swear that the first time I wrote the macro, that is what I did and
it didn't work, and that is what drove me toward what I sent you. I
don't understand what happened.

In any event, I am fine now, and I thank you.

Dean
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF, THEN SYNTAX BBABBZZ Excel Worksheet Functions 5 January 12th 10 10:11 PM
Why is Access VBA syntax different from Excel syntax? cr113 Excel Programming 2 December 2nd 09 12:42 AM
vba syntax Derrick Excel Discussion (Misc queries) 11 August 5th 09 08:37 PM
Need help with syntax James Excel Programming 7 August 28th 08 07:19 PM
Syntax help! Mike Fogleman Excel Programming 20 July 30th 05 01:11 PM


All times are GMT +1. The time now is 12:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"