Hi, I am having a specific issue as part of a much larger project. Quick background--this is for survey research data analysis. So, my data is constantly changing shape and size.
I am trying to create a variable "Denominator" based off a specific location of a cell. I need to then use this variable "Denominator" a few times to determine the proportion or percentages of times a specific answer was provided for each questions.
While I have two major issues right now, the first one to fix is the variable declaration problem.
The code is below, and the variable declaration is bolded. Even after I run the code and hover over the variable name the pop-up box informs me that the variable is Empty. I believe, this explains why I keep receiving #NAME errors when I got to divide my total value by the Denominator variable.
So, my question is what am I doing wrong?
Sub ToplineMultiDay()
Application.ScreenUpdating = False
Dim wrksheet As Worksheet
Dim col As Integer
Dim row As Integer
Dim i As Integer
Dim j As Integer
Dim w As Integer
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim SampleSize As String
Dim lrow As Integer
Dim lcol As Integer
Dim EndRow As Integer
Dim TotalRowEnd As Long
Dim Sheet1 As Range
Dim Denominator As Integer
ActiveSheet.Name = "Sheet1"
'Inserting extra rows
Rows("1:8").Insert Shift:=xlDown
'Changing fonts
Range("A1").Value = "Advantage, Inc."
Range("A1").Select
With selection.Font
.Name = "Cambria"
.Bold = True
.Size = 14
.Color = RGB(192, 0, 0)
.Underline = True
End With
Range("A2") = InputBox("What is the Client's Name?")
Range("A2").Select
With selection.Font
.Name = "Cambria"
.Bold = True
.Size = 12
End With
Columns("A").HorizontalAlignment = xlLeft
Columns("A").ColumnWidth = 19.43
'Columns("C").ColumnWidth = 5.29
'Creating date and commentary
Range("A3").Value = "=TODAY() - 1"
Range("A3").Select
With selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
End With
'Adding more segments
Range("A5").Value = "Start Date"
Range("A6").Value = "End Date"
Range("M8").Value = "Total"
Range("M8").Select
With selection.Font
.Size = 12
.Bold = True
.Name = "Cambria"
End With
Range("N8").Value = "Percentage"
Range("N8").Select
With selection.Font
.Size = 12
.Bold = True
.Name = "Cambria"
End With
Range("N:N").NumberFormat = "0.00%"
'Finding last row
lrow = Cells(Rows.Count, "A").End(xlUp).row
Debug.Print lrow
EndRow = lrow + 2
Debug.Print EndRow
TotalRowEnd = lrow + 74
Debug.Print TotalRowEnd
'Bolding/Change Font
w = 8
Do Until w = EndRow
If Cells(w, 1) = "" Then
Cells(w + 1, 2).Select
With selection.Font
.Bold = True
.Name = "Cambria"
End With
Cells(w + 1, 3).Select
With selection.Font
.Bold = True
.Name = "Cambria"
End With
Cells(w + 1, 1).Select
With selection.Font
.Bold = True
.Name = "Cambria"
End With
End If
w = w + 1
Loop
'Inserting Total rows and adding totals
x = 9
Do Until x = EndRow
If Cells(x, 1) = "" Then
Cells(x, 2).Value = "Total"
Cells(x, 2).Select
With selection.Font
.Bold = True
.Name = "Cambria"
End With
Rows(x).Select
With selection
.Font.Bold = True
.Font.Name = "Cambria"
.NumberFormat = 0
End With
End If
If Cells(x, 2) <> "" Then
Cells(x, 13).FormulaR1C1 = "=SUM(RC4:RC12)"
If Cells(x, 13) = "0" Then
Cells(x, 13).Value = ""
End If
End If
x = x + 1
Loop
'Adding a row between Total and next column
y = 9
Do Until y = TotalRowEnd
If Cells(y, 2) = "Total" Then
Rows(y).Offset(1).EntireRow.Insert
End If
y = y + 1
Loop
i = 9
j = 9
Do Until i = TotalRowEnd
If Cells(i, 2) = "Total" Then
Denominator = Cells(i, 13).Value
End If
While Cells(j, 2) <> ""
If Cells(j, 2) <> "" Then
Cells(j, 14).FormulaR1C1 = "=RC13/" & Denominator & ""
End If
j = j + 1
Wend
i = i + 1
Loop
Range("E:L").EntireColumn.Hidden = True
End Sub
I am open to suggestions for changing the formulation as a whole, I am still fairly new to VBA. So, if anyone thinks of an entirely different and better way to address the issue it is welcomed.
Let me know if there is any additional information that I can provide. I am using excel 2010
Thanks!!
Bookmarks