Referencing a cell within code - VBScript

H7analyst

New Member
Joined
Dec 15, 2011
Messages
1
Using Excel 2007-
So I have a code written to execute a data table (pulling from an external database, which is an add in to excel). The below code works fine and pulls the data but here's the adjustment I need to make. In the 2nd "break", that starts with result=, this is where it chooses where to pull the table and how to pull it by. Currently it is pulling Database "Reporting", It is selecting Year "2011", By Row "Company" and By Column "Year". And it is showing Invoice Extended Price, which are sales. What I need it to do is where the "Company" is, I need it to reference a cell in place of that. So ultimately it would reference cell A1 for example, and whatever is typed in that cell (whether it's Company, or State, or Product), that will get pulled into the chart. Right now it works but it is only showing the table by Company, whereas if I could have it reference a cell, it would make it much easier for someone to select how they want to see the report.


Sub ExecuteScript()
Dim addin As Office.COMAddIn
Dim automationObject As Object
Set addin = Application.COMAddIns("BIReporting")
Set automationObject = addin.Object
Dim result() As Variant

result = automationObject.ExecuteScript("Database ""Reporting""" & vbCrLf & "Select" & vbCrLf & """Year"" ""2011""" & vbCrLf & "End Select" & vbCrLf & "Table ShowHeaders ShowHorizontalGrid ShowVerticalGrid Indent 10" & vbCrLf & "ByRow ""Company"" HideEmptyRows" & vbCrLf & "ByColumn ""Year""" & vbCrLf & "Show ""Invoice Extended Price"" & vbCrLf & "End Table")

Dim size
size = UBound(result, 1)
Dim size2
size2 = UBound(result, 2)
With ActiveSheet
Range(("A3"), .Cells(size + 3, size2 + 1)).Value2 = result
End With

End Sub



Any help is appreciated. Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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