Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using a variable as a Row number

I'm using named cells as a reference in a worksheet.

This is the code that takes me to a cell, and loads that row as a
variable -
in this case 79

Dim r1 As Integer

Application.Goto Reference:="Click_ThankYou"

r1 = ActiveCell.Row

This is the code that the macro generator produces when I do a Insert
-
Names - Define and move the cursor down one cell.

ActiveWorkbook.Names.Add Name:="Click_ThankYou",
RefersToR1C1:= _
"='Clickthrough Detail'!R80C1"

What I'm trying to do is replace the R80C1 with R&r1+1&C1, but i'm
having trouble with the formatting. Does anyone know what the
formatting looks like to replace the 80 with the variable r1+1?

Best Regards,

Phil Hennessy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Using a variable as a Row number

Hi Phil

Without error trapping:

Sub test()
Dim L As Long
L = Val(InputBox("Row:"))
ActiveWorkbook.Names.Add _
Name:="Click_ThankYou", _
RefersToR1C1:= _
"='Clickthrough Detail'!R" & L & "C1"
End Sub

HTH. Best wishes Harald

"Phil Hennessy" skrev i melding
om...
I'm using named cells as a reference in a worksheet.

This is the code that takes me to a cell, and loads that row as a
variable -
in this case 79

Dim r1 As Integer

Application.Goto Reference:="Click_ThankYou"

r1 = ActiveCell.Row

This is the code that the macro generator produces when I do a Insert
-
Names - Define and move the cursor down one cell.

ActiveWorkbook.Names.Add Name:="Click_ThankYou",
RefersToR1C1:= _
"='Clickthrough Detail'!R80C1"

What I'm trying to do is replace the R80C1 with R&r1+1&C1, but i'm
having trouble with the formatting. Does anyone know what the
formatting looks like to replace the 80 with the variable r1+1?

Best Regards,

Phil Hennessy



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using a variable as a Row number

To reset the named range, I would do something like this:

NewRng = "='Clickthrough Detail'!R" & r1 + 1 & "C1"
ActiveWorkbook.Names.Add Name:="Click_ThankYou",
RefersToR1C1:= NewRng

-----Original Message-----
I'm using named cells as a reference in a worksheet.

This is the code that takes me to a cell, and loads that

row as a
variable -
in this case 79

Dim r1 As Integer

Application.Goto Reference:="Click_ThankYou"

r1 = ActiveCell.Row

This is the code that the macro generator produces when I

do a Insert
-
Names - Define and move the cursor down one cell.

ActiveWorkbook.Names.Add Name:="Click_ThankYou",
RefersToR1C1:= _
"='Clickthrough Detail'!R80C1"

What I'm trying to do is replace the R80C1 with

R&r1+1&C1, but i'm
having trouble with the formatting. Does anyone know

what the
formatting looks like to replace the 80 with the variable

r1+1?

Best Regards,

Phil Hennessy
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using a variable as a Row number

if you want to move Click_ThankYou down on row

Range("Click_ThankYou").Offset(1,0).Name = "Click_ThankYou"

--
Regards,
Tom Ogilvy

"Phil Hennessy" wrote in message
om...
I'm using named cells as a reference in a worksheet.

This is the code that takes me to a cell, and loads that row as a
variable -
in this case 79

Dim r1 As Integer

Application.Goto Reference:="Click_ThankYou"

r1 = ActiveCell.Row

This is the code that the macro generator produces when I do a Insert
-
Names - Define and move the cursor down one cell.

ActiveWorkbook.Names.Add Name:="Click_ThankYou",
RefersToR1C1:= _
"='Clickthrough Detail'!R80C1"

What I'm trying to do is replace the R80C1 with R&r1+1&C1, but i'm
having trouble with the formatting. Does anyone know what the
formatting looks like to replace the 80 with the variable r1+1?

Best Regards,

Phil Hennessy



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
Sum over a variable number of cells SD Excel Discussion (Misc queries) 4 April 29th 23 07:44 PM
Variable row number in Sum($A$1:A10) formula Migo1 Excel Discussion (Misc queries) 3 December 3rd 09 09:13 PM
How to sum a variable number of items RobinC Excel Worksheet Functions 2 May 30th 08 08:14 AM
reference with variable row number ? Arc_K Excel Worksheet Functions 7 October 23rd 06 06:47 PM
deleting a variable number of columns Rob Barnard Excel Programming 2 July 28th 03 07:04 PM


All times are GMT +1. The time now is 10:23 PM.

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"