Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA RC1 variables - name error

I am trying to build a sub in Excel vba to create a formula from values
on another sheet.

The code is

Sub Createlinks()
'
' Build formula for summary of weekly accom into main ssheet

'

Dim col1, col2 As Integer


col1 = -23
col2 = col1 + 6


For x = 1 To 35

ActiveCell.FormulaR1C1 = "='A1'!A2 - MAX('A1'!R[-32]C[" & col1 &
"]:R[-32]C[" & col2 & "])"
ActiveCell.Offset(0, 1).Range("A1").Select

col1 = col2
col2 = col1 + 6

Next x


End Sub

All seems to work fine except that the "='A1'!A2 element appears on
the spreadsheet as "='A1'!'A2'
adding in ' ' around A2, this then generates an invalid name range. ??

Why are the extra ' ' being added ?? tried using a string to add in the
"='A1'!A2 element but still i have the same error.

?? Any help gratefully recieved

Mark

Dusting off the cobwebs of VBA knowledge, seem to have forgotten more
than I once knew !!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default VBA RC1 variables - name error

Setting the FormulaR1C1, requires a cell reference in that notation, try
this....

ActiveCell.FormulaR1C1 = "='A1'!R2C1 & - MAX('A1'!R[-32]C[" & col1 &
"]:R[-32]C[" & col2 & "])"


--
Cheers
Nigel



"lensteruk" wrote in message
ups.com...
I am trying to build a sub in Excel vba to create a formula from values
on another sheet.

The code is

Sub Createlinks()
'
' Build formula for summary of weekly accom into main ssheet

'

Dim col1, col2 As Integer


col1 = -23
col2 = col1 + 6


For x = 1 To 35

ActiveCell.FormulaR1C1 = "='A1'!A2 - MAX('A1'!R[-32]C[" & col1 &
"]:R[-32]C[" & col2 & "])"
ActiveCell.Offset(0, 1).Range("A1").Select

col1 = col2
col2 = col1 + 6

Next x


End Sub

All seems to work fine except that the "='A1'!A2 element appears on
the spreadsheet as "='A1'!'A2'
adding in ' ' around A2, this then generates an invalid name range. ??

Why are the extra ' ' being added ?? tried using a string to add in the
"='A1'!A2 element but still i have the same error.

?? Any help gratefully recieved

Mark

Dusting off the cobwebs of VBA knowledge, seem to have forgotten more
than I once knew !!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VBA RC1 variables - name error

Nigel you are a star, needed to change a few things and put in a
variable which keeps the reference to the static element but got it
sussed now. Many thanks indeed

Mark

Nigel wrote:
Setting the FormulaR1C1, requires a cell reference in that notation, try
this....

ActiveCell.FormulaR1C1 = "='A1'!R2C1 & - MAX('A1'!R[-32]C[" & col1 &
"]:R[-32]C[" & col2 & "])"


--
Cheers
Nigel



"lensteruk" wrote in message
ups.com...
I am trying to build a sub in Excel vba to create a formula from values
on another sheet.

The code is

Sub Createlinks()
'
' Build formula for summary of weekly accom into main ssheet

'

Dim col1, col2 As Integer


col1 = -23
col2 = col1 + 6


For x = 1 To 35

ActiveCell.FormulaR1C1 = "='A1'!A2 - MAX('A1'!R[-32]C[" & col1 &
"]:R[-32]C[" & col2 & "])"
ActiveCell.Offset(0, 1).Range("A1").Select

col1 = col2
col2 = col1 + 6

Next x


End Sub

All seems to work fine except that the "='A1'!A2 element appears on
the spreadsheet as "='A1'!'A2'
adding in ' ' around A2, this then generates an invalid name range. ??

Why are the extra ' ' being added ?? tried using a string to add in the
"='A1'!A2 element but still i have the same error.

?? Any help gratefully recieved

Mark

Dusting off the cobwebs of VBA knowledge, seem to have forgotten more
than I once knew !!


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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Overflow error when declaring variables Jeff Excel Discussion (Misc queries) 2 January 9th 08 03:15 PM
Error in setting formula (Match) with dynamic variables John Wong[_2_] Excel Programming 2 November 8th 06 04:35 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Setting Public Variables Error clmarquez[_10_] Excel Programming 8 January 16th 06 05:25 PM


All times are GMT +1. The time now is 02:49 AM.

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

About Us

"It's about Microsoft Excel"