excel-vba

Runtime error '1004' while creating a pivot table

穿精又带淫゛_ 提交于 2020-01-05 20:27:42
问题 I am trying to create a pivot table after copying the data from one workbook to another workbook. Here is the code. Dim ws As Worksheet Set ws = Sheets.Add ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ "PIVOT_RANGE", Version:=xlPivotTableVersion14). _ CreatePivotTable TableDestination:=ws.Name & "!R1C1", TableName:= _ "PivotTable2", DefaultVersion:=xlPivotTableVersion14 I am seeing different pivot table name every time. Sometimes it shows PivotTable1 and Sometimes

How do I suppress Excel message for any pivot table update?

故事扮演 提交于 2020-01-05 20:02:32
问题 I have created a pivot table to summarize some information and have added some formulas adjacent to the pivot table to do calculations on the numbers included in it. I have created a macro that re-enters the formulas whenever the user changes the size of the pivot table (in the PivotTableUpdate event) by showing or hiding various rows/columns of data. My problem is that whenever columns of data are added to the pivot table, it asks me "Do you want to replace the contents of the destination

Conditional Formatting Excel document via VB6 (issue with overwriting formats)

情到浓时终转凉″ 提交于 2020-01-05 19:23:58
问题 I'm creating an Excel document at runtime that has a bunch of values I'd like to have conditionally formatted. In going through various attempts from scratch as well as using/modifying code outputted from the Excel's macro recorder, I'm having a consistent issue related to formatting overwrites. I've posted a snippet of the code below and can say that I've tested to ensure my selection ranges are valid and appropriate for what I want conditionally formatted. There is some overlap but what's

Conditional Formatting Excel document via VB6 (issue with overwriting formats)

你离开我真会死。 提交于 2020-01-05 19:23:29
问题 I'm creating an Excel document at runtime that has a bunch of values I'd like to have conditionally formatted. In going through various attempts from scratch as well as using/modifying code outputted from the Excel's macro recorder, I'm having a consistent issue related to formatting overwrites. I've posted a snippet of the code below and can say that I've tested to ensure my selection ranges are valid and appropriate for what I want conditionally formatted. There is some overlap but what's

Open save window in file path from a cell well also populateing filename from cell

依然范特西╮ 提交于 2020-01-05 16:52:13
问题 i have a workbook that i use as a template to make estimates that when i'm done filling out the template there is a macro that creates a new workbook and copies all the sheets of the template workbook to the new one and then removes all the formulas and info i don't want the customer to see. Here's part of my code that creates the new workbook and copies all the sheets from the template to the new one and then cleans it up Sub TestConvert() 'Disabling the following to speed up the vba code,

How to select multiple shapes based on range?

一个人想着一个人 提交于 2020-01-05 16:50:21
问题 If the selected range is composed of 1 cell then select all shapes in the sheet, else select the shapes in the range. It's the "else" part that's giving me trouble. I can select one shape, but not all shapes in the range... Public Sub ShapeSelection() Dim Sh As Shape On Error Resume Next If Selection.Rows.count * Selection.Columns.count = 1 Then ActiveSheet.Shapes.SelectAll Else Application.ScreenUpdating = False With ActiveSheet For Each Sh In .Shapes If Not Application.Intersect(Sh

How to select multiple shapes based on range?

我是研究僧i 提交于 2020-01-05 16:50:06
问题 If the selected range is composed of 1 cell then select all shapes in the sheet, else select the shapes in the range. It's the "else" part that's giving me trouble. I can select one shape, but not all shapes in the range... Public Sub ShapeSelection() Dim Sh As Shape On Error Resume Next If Selection.Rows.count * Selection.Columns.count = 1 Then ActiveSheet.Shapes.SelectAll Else Application.ScreenUpdating = False With ActiveSheet For Each Sh In .Shapes If Not Application.Intersect(Sh

VBA - selecting a folder and referencing it as the path for a separate code

廉价感情. 提交于 2020-01-05 15:17:09
问题 I'm able to use this code to select a folder: Sub ChooseFolder() Dim fldr As FileDialog Dim sItem As String Set fldr = Application.FileDialog(msoFileDialogFolderPicker) With fldr .Title = "Select a Folder" .AllowMultiSelect = False .InitialFileName = strPath If .Show <> -1 Then GoTo NextCode sItem = .SelectedItems(1) End With NextCode: GetFolder = sItem Set fldr = Nothing End Sub I also have this code, that works when the folder path is hardcoded. Basically, it gives me a list of file names

Run time error Unrecognized database while exporting data from excel 2010 to Access table 2010 using excel vba

混江龙づ霸主 提交于 2020-01-05 15:07:06
问题 I have a table in Access 2010 db with same column names as the column names in excel sheet. I have to delete Access table data content before pumping data from my macro enalbed excel 2010 sheet into it.For now I m trying to see/test if I could pump my excel data to empty table in Access. Once I get this working, I could get 'delete content before dumping excel data' working. Here's my excel vba macro code: Sub ADOFromExcelToAccess() 'exports data from the active worksheet to a table in an

Why does my code run without 'Option Explicit' but fail with it?

风流意气都作罢 提交于 2020-01-05 14:12:10
问题 I am constructing my first major program in VBA (With some help from SO). The beginning of it is below, and I am adding blocks of code in as structured a way as possible. Having read about the importance of using 'Option Explicit' though, I inserted it and started to declare all my variables. Running the program gave - 'Compile Error: Variable not Defined'. I have tried deleting and re-entering declarations in case the problem was caused by me adding 'Option Explicit' after starting on the