Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

variables in a function in excel macro


  • Please log in to reply

#1
vinu-kp

vinu-kp

    New Member

  • Member
  • Pip
  • 1 posts
Could some one help me out???

the line below works perfectly in my vb macro for excel

ActiveCell.FormulaR1C1 = "=SUM(R[-20]C:R[-1]C)"

-----------------------------------------------

Now I want to use variables instead of values. i.e. store -20 and -1 in variables row2 and row1.


When i try the following line with variable row1 and row2 instead of -1 and -20

ActiveCell.FormulaR1C1 = "=SUM(R[row2]C:R[row1]C)"


i get an error message saying " Runtime error : 1004. Application-defined or object-defined error" .


I dont understand why i am getting this error. I have defined row1 and row2 as integers.

I am new to macros and i couldnt manage any help from anywhere in excel or vb.

Pleaseeeeeee help meeeeee

Vinu
  • 0

Advertisements


#2
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
variables in vb or macros(same thing but called VBA) are intialized at the start of the run time

unless you state what row1 or row2 equal at the beginning of teh program then u will keep getting errors because the macdro does not know what row1 and erow2 are

if you want i can show you what to type to make row1 = row1 in the sheet

otherwise keep using what u have
ActiveCell.FormulaR1C1 = "=SUM(R[row2]C:R[row1]C)"

Stu Design
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP