I am working with list objects in excel and there is one thing that puzzles me:
according to this and many other sites I visited the following line of code is a range:
mytable.headerRowRange("nameofColumn")
mytable being a listobject of a particular sheet.
what I wand to do is hide that column
but this would not work:
mytable.headerRowRange("nameofColumn").EntireColumn.Hidden=True
Why?
the error is: Invalid procedure call or argument.
thanks.
mytable.ListColumns("ID").Range.EntireColumn.Hidden = True
You could also have done
mytable.HeaderRowRange.Find("id").EntireColumn.Hidden = True
Related
I am trying to adjust some workbook audit code for the new threaded comments. Basically the code would cycle through all workbook comments (notes) and consolidate them into a new sheet at the end of the workbook.
With what is now notes, I use the following (noting cmt1 is declared as a comment object and wsSource is a worksheet object)
For Each cmt1 In wsSource.Comments
'Collect comment data for testing/pasting
strSheetname = wsSource.Name
strCmt = cmt1.Text
strCellref = cmt1.Parent.Address
strContent = cmt1.Parent.Formula
etc.
Now with threaded comments, the same type of approach didn't work. I am trying to do a numerical loop using a counter and having code like the below:
For x = 1 to wsSource.commentsthreaded.count
However the count property doesn't work. According to the nmicrosoft website, it should be one of the 4 available properties.
https://learn.microsoft.com/en-us/office/vba/api/excel.commentsthreaded
Does anyone else have this issue? Any way to fix it?
Issue resolved - it looks like the problem was the Excel version. I was running 1904 and it now works since updating to 1906.
I have the following code to ensure that only a single value is selected on the relevant pivot field - however I keep getting the error "unable to set the currentpage property of the pivot field" - I don't understand why as I used a the same code for a different filter.
Sub filters()
Dim PRC As PivotField
Sheets("workings-calc").Select
Set PRC = ActiveSheet.PivotTables("PivotTable3").PivotFields("PR_CD")
PRC.ClearAllFilters
PRC.CurrentPage = "PR-500001"
End Sub
Appreciate any help on this. Have spent far too long trying to get this to work without success :/
The following code works and gets me the desired output.
for each itm1 in prc.pivotitems
if item 1.name = "PR-500001" then
else
itm1.visible = false
next
the above code leaves only the filter specified selected on the pivot field.
Thanks for all the input.
I am trying to hide and unhide series in a chart based on their name using excel vba and I have a error 1004 invalid parameter after the first run of the for cycle.
Sub macroChart3()
'
' macroChart3 Macro test
'
Dim i, n As Integer
For i = 1 To 96 Step 1
If ActiveChart.SeriesCollection(i).Name = "*contracted*" Then
ActiveChart.SeriesCollection(i).IsFiltered = False
Else
ActiveChart.SeriesCollection(i).IsFiltered = True
End If
Next i
End Sub
SeriesCollection.IsFiltered method seemed to toggle this check box:
I couldn't use that. I wanted to record macro and see if any other method is used but the checkbox is gone in 2010:
So it might be not possible to use that anymore. If you are using a different version where this method exists you might have a problem that the series is not listed in in seriesCollection anymore:
Remarks from MSDN
When a user filters out a series, the series IsFiltered property switches to True, and the series is transferred out of its parent SeriesCollection.
See if you can use FullSeriesCollection instead when you change the visibility of series:
ActiveChart.FullSeriesCollection(2).IsFiltered = True
If that doesn't work you might add and remove ranges instead of hiding them.
UPDATE:
Run your macro in step mode (F8) so you have full visibility of the execution steps. Add your evaluated expressions (ones that are used within IFs) to see their result and you will find out if they are incorrect or are evaluated as FALSE and try to figure out why.
And don't forget to up vote the answer if you find it helpful.
thanks for the quick reply, the error is fixed, but still not all the series are processed by the if clauses in the for cycle, for example this statement:
Else
ActiveChart.SeriesCollection(i).IsFiltered = True
End If
Isn't executed and I don't understand why.
I have a VBA procedure (in Excel 2007) where I aspire to set the ListFillRange property of a combobox styled as a list using an array.
I know this works if I right click the combobox and write "Sheet1!$F2:$F17" next to the "ListFillRange" property. I can also do this in code. However, I am interested in dynamically setting the value of this property by assigning it an array.
I know for sure the array works as I tested it; there is probably a syntax error here:
ThisWorkbook.Worksheets("Sheet1").OLEObjects("cmbS").ListFillRange = ar
when I do this I get:
"Type mismatch" error.
The result of this action should be that the component is populated with the array elements, from element(0) ... to the last element (n-1) of the array. Any pointers, thank you very much!
I also tried:
ThisWorkbook.Worksheets("Sheet1").cmbS.list = ar
and it says "permission denied"
Here are the combobox properties in case it helps:
After testing and trying, I found this works:
ThisWorkbook.Worksheets("Sheet1").cmbS.ListFillRange = ""
Dim i As Integer
For i = LBound(ar) To UBound(ar)
ThisWorkbook.Worksheets("Sheet1").cmbS.AddItem (ar(i))
Next
However, I am interested in populating with all values at once for faster effect, not just adding element by element.
I know its late but maybe it is going to help someone else. At least the following code works (much faster than element for element) for me.
dim arr() as variant
arr = Worksheets("Total").Range("C2:"&lrow).Value
Worksheets("Menu").ComboBox2.List = arr
The only way you can populate a combobox with the content of an array is by doing it element by element. I find it hard to believe that it would be a notably slow process no matter how large your array is.
I want to select some values through VBA in Pivot Table which is linked to OLAP Cube.
As I know such modification can be realised by typing:
ActiveSheet.PivotTables("PivotTable1").PivotFields("[parameter].[parameter]").VisibleItemsList = Array("value1","value2","value3")
Since get list of parameters from cells in Excel sheet, I wrote simple function which - In mentioned example - returns:
""value1","value2","value3""
I can't use such string as parameter for Array function (as it recognize it as one string), so I've tried to convert it to Array of Variant, typing above code:
Dim tableVar() As Variant
myVar = Replace(myVar, Chr(34), "")
myVar = Split(myVar, ",")
lowerB =LBound(myVar)
upperB = UBound(myVar)
ReDim tablica(lowerB To upperB)
For i = lowerB To upperB
tableVar(i) = myVar(i)
Next i
Unfortunately it changes nothing - when I'm calling:
ActiveSheet.PivotTables("PivotTable1").PivotFields("[parameter].[parameter]").VisibleItemsList = tableVar
I'm still receiving an error message.
Could you help me, please?
you have a typo in your code, daty should say myVar.
(Either that or we're missing more details)
Stupid thing, but error message is simply correct - there's no such items in Cube:
Run-time error '1004': The item could not be found in the OLAP Cube
I gave incorrect parameter here:
ActiveSheet.PivotTables("PivotTable1").PivotFields("[parameter].[parameter]").VisibleItemsList = tableVar
My code was unnecessary complicated - sorry for wasting your time.
Now my problem will be - how to check if specific dimensions or whole Cube exist...
Thanks once more for help.