Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

variables in a function in excel macro

  • Please log in to reply



    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

  • 0





  • 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