Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Problem referencing a cell using 2 variables

I am having trouble referencing a cell using two variables (in this
case the variables are tbindex1 and chindex1). II have included the
code below. Anyone know a solution?

Sub PrintMacro()

Dim wks As Worksheet
Dim N As Long
Dim TableRange1 As String
Dim TableRange2 As String
Dim TableRange3 As String
Dim TableRange4 As String
Dim TableRange5 As String
Dim TableRange6 As String
Dim ChartRange1 As String
Dim ChartRange2 As String
Dim ChartRange3 As String
Dim ChartRange4 As String




'Define ranges
mdindex1 = Sheets("Cover").range("E13").Value
modelrange = "B5:" + mdindex1 + "$36,B38:" + mdindex1 + "83"
tbindex1 = Sheets("Cover").range("E14").Value
chindex1 = Sheets("Cover").range("D18").Value
chindex2 = Sheets("Cover").range("D19").Value
chindex3 = Sheets("Cover").range("D20").Value
chindex4 = Sheets("Cover").range("D21").Value


TableRange1 = "$A$4:$" + tbindex1 + "$45"
TableRange2 = "$A$47:$" + tbindex1 + "$88"
TableRange3 = "$A$91:$" + tbindex1 + "$132"
TableRange4 = "$A$135:$" + tbindex1 + "$176"
TableRange5 = "$A$179:$" + tbindex1 + "$220"
TableRange6 = "$A$223:$" + tbindex1 + "$264"


ChartRange1 = "$c$4:$" + tbindex1 + "$" + chindex1
ChartRange2 = "$c$47:$" + tbindex1 + "$" chindex2
ChartRange3 = "$c$91:$" + tbindex1 + "$" chindex3
ChartRange4 = "$c$135:$" + tbindex1 + "$" chindex4


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Problem referencing a cell using 2 variables

Change plus signs to Ampersand ("&"). String are combined with & not plus
signs. When you use plus signs VBA thinks yo are combining numbers not
strings.

modelrange = "B5:" & mdindex1 & "$36,B38:" & mdindex1 & "83"

" wrote:

I am having trouble referencing a cell using two variables (in this
case the variables are tbindex1 and chindex1). II have included the
code below. Anyone know a solution?

Sub PrintMacro()

Dim wks As Worksheet
Dim N As Long
Dim TableRange1 As String
Dim TableRange2 As String
Dim TableRange3 As String
Dim TableRange4 As String
Dim TableRange5 As String
Dim TableRange6 As String
Dim ChartRange1 As String
Dim ChartRange2 As String
Dim ChartRange3 As String
Dim ChartRange4 As String




'Define ranges
mdindex1 = Sheets("Cover").range("E13").Value
modelrange = "B5:" + mdindex1 + "$36,B38:" + mdindex1 + "83"
tbindex1 = Sheets("Cover").range("E14").Value
chindex1 = Sheets("Cover").range("D18").Value
chindex2 = Sheets("Cover").range("D19").Value
chindex3 = Sheets("Cover").range("D20").Value
chindex4 = Sheets("Cover").range("D21").Value


TableRange1 = "$A$4:$" + tbindex1 + "$45"
TableRange2 = "$A$47:$" + tbindex1 + "$88"
TableRange3 = "$A$91:$" + tbindex1 + "$132"
TableRange4 = "$A$135:$" + tbindex1 + "$176"
TableRange5 = "$A$179:$" + tbindex1 + "$220"
TableRange6 = "$A$223:$" + tbindex1 + "$264"


ChartRange1 = "$c$4:$" + tbindex1 + "$" + chindex1
ChartRange2 = "$c$47:$" + tbindex1 + "$" chindex2
ChartRange3 = "$c$91:$" + tbindex1 + "$" chindex3
ChartRange4 = "$c$135:$" + tbindex1 + "$" chindex4



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
cell referencing with variables Liesbeth Excel Programming 2 March 9th 07 01:07 PM
referencing a value from a chart with 3 variables KP@RG New Users to Excel 1 December 12th 06 02:29 PM
Referencing Controls Using Variables Teodomiro[_3_] Excel Programming 4 April 28th 06 06:21 PM
referencing with variables mpele Excel Programming 1 March 8th 06 10:22 AM
Referencing Variables Dwinmac Excel Worksheet Functions 1 November 16th 04 06:18 PM


All times are GMT +1. The time now is 04:21 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"