Evaluate as in a cell

KillGorack

New Member
Joined
Jan 23, 2006
Messages
35
Office Version
  1. 2016
Platform
  1. Windows
Hey,


Previous answer showed this is possible, but tried the code below, but when ran each cell has #VALUE! within.

any ideas?

VBA Code:
Sub populateBindField()

    ' ===============================================================
    ' Declarations
    ' ===============================================================
        Dim x As Integer
        Dim tempheight As Integer
        Dim tempwidth As Integer
        Dim r As String
    ' ===============================================================
    ' Size it up
    ' ===============================================================
        tempheight = ThisWorkbook.Sheets("raw data").Cells(Rows.Count, 1).End(xlUp).Row
        tempwidth = ThisWorkbook.Sheets("raw data").Cells(1, Columns.Count).End(xlToLeft).Column
    ' ===============================================================
    ' Subtotals.
    ' ===============================================================
        For x = 21 To tempwidth
            r = "SUBTOTAL(9, RANGE(ThisWorkbook.Sheets(" & Chr(34) & "raw data" & Chr(34) & ").cells(2, " & x & "), ThisWorkbook.Sheets(" & Chr(34) & "raw data" & Chr(34) & ").cells(" & tempheight & ", " & x & ")))"
            ThisWorkbook.Sheets("output").Cells(36, x - 20).Value = Evaluate(r)
        Next x
    ' ===============================================================
  
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Which "formula" would you like to obtain and be evaluated??
 
Upvote 0
Sorry, the subtotal isn't working when I evaluate it. Starting with r=.

Or an example of evaluating a subtotal using a range defined without column letters but numbers instead. Does that make sense?
 
Upvote 0
You should get in R something like SUBTOTAL(9,'raw data'!C4:C9) but I cannot guess which area you wish to calculate, and reverse engineering your r = etc etc didn't help
 
Upvote 0
Maybe
VBA Code:
            r = "SUBTOTAL(9," & Chr(39) & "raw data'!" & Cells(2, x).Address & ":" & Cells(tempheight, x).Address & ")"
This will create in r: SUBTOTAL(9,'raw data'!$U$2:$U$9)
(tempheight is 9 in my test sheet)

Bye
 
Upvote 0
Solution
You should get in R something like SUBTOTAL(9,'raw data'!C4:C9) but I cannot guess which area you wish to calculate, and reverse engineering your r = etc etc didn't help

Understood I have too much code there.. too the point.. in your code where you have the letter "C" is my issue, I want to use numbers instead.

So instead of using

Excel Formula:
=SUBTOTAL(9, 'raw data'!U2:U1890)

I need to set the range using numbers instead similar to;

VBA Code:
Sheets("output").Cells(36, x - 20).Value = Evaluate(SUBTOTAL(9, RANGE(Sheets("raw data").cells(2, 21), Sheets("raw data").cells(1890, 21))))

Is it more clear? I cant get the code above to work either.
 
Upvote 0
Did you see my message in post #5, timed 2 minutes before your latest one?
 
Upvote 0
Did you see my message in post #5, timed 2 minutes before your latest one?

No i didn't trying now,...

<edit>
Yup that works.. new sytax for me I will get my head around it.. Freaking awesome.
</edit>
 
Upvote 0
Maybe
VBA Code:
            r = "SUBTOTAL(9," & Chr(39) & "raw data'!" & Cells(2, x).Address & ":" & Cells(tempheight, x).Address & ")"
This will create in r: SUBTOTAL(9,'raw data'!$U$2:$U$9)
(tempheight is 9 in my test sheet)

Bye

Yea OK my issue was trying to add VB code into a cell somehow.. that looks more like a cell function.. it was a total brain burp.. thanks!
 
Upvote 0
..and of course you could use also WorksheetFunction:
VBA Code:
ThisWorkbook.Sheets("output").Cells(36, x - 20).Value = Application.WorksheetFunction.Subtotal(9, Sheets("raw data").Cells(2, x).Resize(tempheight, 1))

There are many options, so keep trying, it's the only way for learning

Bye
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top