Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
cell referencing with variables | Excel Programming | |||
referencing a value from a chart with 3 variables | New Users to Excel | |||
Referencing Controls Using Variables | Excel Programming | |||
referencing with variables | Excel Programming | |||
Referencing Variables | Excel Worksheet Functions |