Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

What's wrong with this?

  Asked By: Meenachi    Date: Dec 09    Category: MS Office    Views: 640
  

ActiveCell.Rows("1:p").EntireRow.Select

(error=type mismatch)
(p is Dim'd as Integer, in this case p = 220)
(it works if I just plug in the 220, but it doesn't like this use of
the variable--although it seems like I've done this before)

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Mena Schmidt     Answered On: Dec 09

P is inside the quotes, so it is just "p".

You need it outside the quotes

ActiveCell.Rows("1:" & p).EntireRow.Select

 
Answer #2    Answered By: Jessie Banks     Answered On: Dec 09

the logic of the syntax eludes me--I guess it's just
something I'll have to memorize . . .and remember . . .

 
Answer #3    Answered By: Sam Evans     Answered On: Dec 09

In some computer programming languages it is possible to
place variable names inside quotes and have the language
interpreter interpolate the value. Perl scalar variables, for
example start with a "$".

This prints "1:220" (without the quotes) in Perl.

my $p = 220;
print "1:$p";


In VBA, variable names do not have a sigil (like $ or @)
in front of them. It is more difficult to interpolate variables
inside quotes when variable names look like common words. The
VBA language writers decided that they would avoid confusion
by not interpolating variable names.

If they had not decided this, we would have problems
printing this.

Dim p as Integer
p = 220
Debug.Print " Have a Happy Day!"

With interpolation this would print the following in the
immediate window.

 
Answer #4    Answered By: Gregg Bennett     Answered On: Dec 09

Your syntax "1:p" was a quoted string with three characters in it: a
numerical 1, a colon, and a lower-case "p".

My syntax "1:" & p is a string concatenation operation that will concatenate
"1:" with the contents of the variable p.

Do some string operations in normal code and you'll become familiar with the
syntax.

 
Didn't find what you were looking for? Find more on What's wrong with this? Or get search suggestion and latest updates.




Tagged: