Help with using user input data variable in VBA code for creating Pivot Table from Excel query PLEASE HELP :(

mwebb

New Member
Joined
Mar 17, 2016
Messages
9
Hello,

I have been trying to figure this out all day and I cant seem to get it. I have VBA code to create pivot tables from the workbook data model. I added data to it already by using the New Query > Workbook > Create Connection / Add to data model. The table I added from the query is "Table2".

I want to have the user rename from "Table 2" to "MMDDYY_W#" (ie "032116 W1") when they make the connection. So I use this:


Code:
    Dim inputData As Variant    inputData = InputBox("Enter Workbook Connection:", "Input Box Text")
    If inputData <> "" Then
        MsgBox inputData
    End If

Next, I have a macro to create pivot tables from the data. It currently works, but I want replace "[Table2]" with the inputData variable throughout so that the macro will pull from the correct data source. An example:

Code:
With ActiveSheet.PivotTables("FSBH_Regular_Units").CubeFields("Table2].[Staff]")        .Orientation = xlRowField
        .Position = 1
    End With

I have researched as much as I could but I can't seem to find or understand the answer.

Thanks.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
mod can delete I created another thread with the question worded more clearly. Sorry.
 
Upvote 0

Forum statistics

Threads
1,215,492
Messages
6,125,115
Members
449,206
Latest member
burgsrus

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