Problem referencing a cell using 2 variables

A

akbnsl

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
 
J

Joel

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top