"Method or data member not found" error message - excel

So at the moment I have this piece of code and when I press the button that runs it the error "Method or data member not found" and it highlights the line "Question13.hide"
I have reused the same piece of code for all of my user forms and it only gives me the error on screen 13, why is this happening?
Private Sub CommandButton1_Click()
'Option 1
If CheckBox1.Value = True Then Worksheets("Results").Range("D54").Value = True
If CheckBox1.Value = True Then Worksheets("Results").Range("D54").Interior.ColorIndex = 10
If CheckBox1.Value = True Then Worksheets("Results").Range("D54").Font.Bold = True
If CheckBox1.Value = False Then Worksheets("Results").Range("D54").Value = False
If CheckBox1.Value = False Then Worksheets("Results").Range("D54").Interior.ColorIndex = 3
If CheckBox1.Value = False Then Worksheets("Results").Range("D54").Font.Bold = True
'Option 2
If CheckBox2.Value = True Then Worksheets("Results").Range("E54").Value = True
If CheckBox2.Value = True Then Worksheets("Results").Range("E54").Interior.ColorIndex = 10
If CheckBox2.Value = True Then Worksheets("Results").Range("E54").Font.Bold = True
If CheckBox2.Value = False Then Worksheets("Results").Range("E54").Value = False
If CheckBox2.Value = False Then Worksheets("Results").Range("E54").Interior.ColorIndex = 3
If CheckBox2.Value = False Then Worksheets("Results").Range("E54").Font.Bold = True
'Option 3
If CheckBox3.Value = True Then Worksheets("Results").Range("F54").Value = True
If CheckBox3.Value = True Then Worksheets("Results").Range("F54").Interior.ColorIndex = 10
If CheckBox3.Value = True Then Worksheets("Results").Range("F54").Font.Bold = True
If CheckBox3.Value = False Then Worksheets("Results").Range("F54").Value = False
If CheckBox3.Value = False Then Worksheets("Results").Range("F54").Interior.ColorIndex = 3
If CheckBox3.Value = False Then Worksheets("Results").Range("F54").Font.Bold = True
'Option 4
If CheckBox4.Value = True Then Worksheets("Results").Range("G54").Value = True
If CheckBox4.Value = True Then Worksheets("Results").Range("G54").Interior.ColorIndex = 10
If CheckBox4.Value = True Then Worksheets("Results").Range("G54").Font.Bold = True
If CheckBox4.Value = False Then Worksheets("Results").Range("G54").Value = False
If CheckBox4.Value = False Then Worksheets("Results").Range("G54").Interior.ColorIndex = 3
If CheckBox4.Value = False Then Worksheets("Results").Range("G54").Font.Bold = True
Question13.Hide
Question14.Show
End Sub

Rather than copying the code onto each form put this into module
Sub UpdateSheet(ByRef frm As UserForm, ByRef rng As Range)
Dim i As Integer, chk As Object
For i = 1 To 4
Set chk = frm.Controls.Item("CheckBox" & i)
rng.Value = chk.Value
rng.Font.Bold = True
If chk.Value = True Then
rng.Interior.ColorIndex = 10
Else
rng.Interior.ColorIndex = 3
End If
Set rng = rng.Offset(0, 1)
Next
End Sub
and then put this code on each form changing the "D54" and Userform2 to suit each question
Private Sub CommandButton1_Click()
' form Question 1
Dim rng As Range
Set rng = ThisWorkbook.Sheets("Results").Range("D54")
Module1.UpdateSheet Me, rng
Me.Hide
UserForm2.Show
End Sub

Related

Checkboxes to hide / show tables on another worksheet

On this page you check what sections will be part of the change order and then click the command button. (The checkboxes don't line up, I'll fix it later.)
Once you click the button I want to use VBA to change a template sheet to only show the tables associated with the boxes checked. Then the template sheet is copied and named based on entries.
The problem is that the unwanted tables are not hidden.
When I check just the first box that works, also checking all boxes works.
The tables look like this:
EDIT- After using debug it seems my tables are not being identified. For example the one I have as rng1 "laborhourly" is hiding rows 3-21 instead of 17-22
Also if I change it from
rng1.CurrentRegion.EntireRow.Hidden = False
to
rng1.EntireRow.Hidden = False
it does not hide extra rows, but the table header is still there.
Private Sub CommandButton1_Click()
Dim rng As Range
Dim ars As Areas
Set wb = Sheets("New Change Order Request")
Set ws = Sheets("RFCO")
ws.Range("1:60").EntireRow.Hidden = False
Set rng1 = ws.Range("laborhourly").CurrentRegion
Set rng2 = ws.Range("laborot").CurrentRegion
Set rng3 = ws.Range("laborprem").CurrentRegion
Set rng4 = ws.Range("equip").CurrentRegion
Set rng5 = ws.Range("rental").CurrentRegion
Set rng6 = ws.Range("subs").CurrentRegion
Set rng7 = ws.Range("materials").CurrentRegion
Set rng8 = ws.Range("other").CurrentRegion
If wb.Range("c10") = True Then
ws.Range("1:15").EntireRow.Hidden = False
rng1.CurrentRegion.EntireRow.Hidden = False
ws.CommandButton1.Visible = True
Else
rng1.EntireRow.Hidden = False
rng1.EntireRow.Hidden = True
ws.CommandButton1.Visible = False
End If
If wb.Range("c11") = True Then
ws.Range("1:15").EntireRow.Hidden = False
rng2.EntireRow.Hidden = False
ws.CommandButton2.Visible = True
Else
ws.Range("1:15").EntireRow.Hidden = False
rng2.EntireRow.Hidden = True
ws.CommandButton2.Visible = False
End If
If wb.Range("c12") = True Then
rng3.EntireRow.Hidden = False
ws.CommandButton3.Visible = True
Else
rng3.EntireRow.Hidden = False
ws.CommandButton3.Visible = True
End If
If wb.Range("c13") = True Then
rng4.EntireRow.Hidden = False
ws.CommandButton4.Visible = True
Else
rng4.EntireRow.Hidden = True
ws.CommandButton4.Visible = False
End If
If wb.Range("c14") = True Then
rng5.EntireRow.Hidden = False
Worksheets("RFCO").CommandButton5.Visible = True
Else
rng5.EntireRow.Hidden = True
ws.CommandButton5.Visible = False
End If
If wb.Range("c15") = True Then
ws.Range("1:15").EntireRow.Hidden = False
ws.Range("subs").CurrentRegion.EntireRow.Hidden = False
Worksheets("RFCO").CommandButton6.Visible = True
Else
ws.Range("subs").CurrentRegion.EntireRow.Hidden = True
ws.CommandButton6.Visible = False
End If
If wb.Range("c16") = True Then
rng7.EntireRow.Hidden = False
Worksheets("RFCO").CommandButton7.Visible = True
Else
rng7.EntireRow.Hidden = True
ws.CommandButton7.Visible = False
End If
If wb.Range("c17") = True Then
rng8.EntireRow.Hidden = False
Worksheets("RFCO").CommandButton8.Visible = True
Else
rng8.EntireRow.Hidden = True
ws.CommandButton8.Visible = False
End If
MsgBox ("DONE")
End Sub

Why does my VBA code throw the Runtime Error 1004 when I am trying to have a button on another worksheet run this macro? Below is the code processed

Below is the code I want to run. I want to be able to click a button on one page and have the other page run this on the pivot table. I will also include the code for the button, which actually my be what is causing the issue.
Private Sub CommandButton1_Click()
Call OHPivot_Store80
End Sub
Sub OHPivot_Store80()
'
' OHPivot_Store80 Macro
'
'
ActiveSheet.PivotTables("PivotTable1").PivotFields("StoreNumber").CurrentPage _
= "(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("StoreNumber")
.PivotItems("0").Visible = False
.PivotItems("6").Visible = False
.PivotItems("22").Visible = False
.PivotItems("24").Visible = False
.PivotItems("40").Visible = False
.PivotItems("44").Visible = False
.PivotItems("48").Visible = False
.PivotItems("50").Visible = False
.PivotItems("54").Visible = False
.PivotItems("56").Visible = False
.PivotItems("58").Visible = False
.PivotItems("60").Visible = False
.PivotItems("62").Visible = False
.PivotItems("64").Visible = False
.PivotItems("70").Visible = False
.PivotItems("72").Visible = False
.PivotItems("74").Visible = False
.PivotItems("76").Visible = False
.PivotItems("78").Visible = False
.PivotItems("82").Visible = False
.PivotItems("84").Visible = False
.PivotItems("86").Visible = False
.PivotItems("88").Visible = False
.PivotItems("90").Visible = False
.PivotItems("92").Visible = False
.PivotItems("94").Visible = False
.PivotItems("96").Visible = False
.PivotItems("98").Visible = False
.PivotItems("110").Visible = False
.PivotItems("(blank)").Visible = False
End With
End Sub
Change the code that responds to the button click to active the sheet that has the pivot table as follows:
Private Sub CommandButton1_Click()
Worksheets.Activate("NAME_OF_SHEET_WITH_PIVOT_TABLE")
Call OHPivot_Store80
End Sub

InCorrect Parameter (VBA Script)

Please help - everything seems correct but still getting incorrect parameter.
Sub Display_Tab_Sales_Revenue()
With ActiveSheet
'Visisbility of Tab Buttons
.Shapes("Revenue_Inactive").Visible = False
.Shapes("Revenue_Active").Visible = True
.Shapes("Units_Inactive").Visible = True
.Shapes("Units_Active").Visible = False
'visibility of Tab Contents
.Shapes("Map_Chart_Sales_Revenue").Visible = True
.Shapes("Line_Chart_Sales_Revenue").Visible = True
.Shapes("Map_Chart_Sales_Units").Visible = False
.Shapes("Line_Chart_Sales_Units").Visible = False
End With
End Sub
Sub Display_Tab_Sales_Units()
With ActiveSheet
'Visisbility of Tab Buttons
.Shapes("Revenue_Inactive").Visible = True
.Shapes("Revenue_Active").Visible = False
.Shapes("Units_Inactive").Visible = False
.Shapes("Units_Active").Visible = True
'visibility of Tab Contents
.Shapes("Map_Chart_Sales_Revenue").Visible = False
.Shapes("Line_Chart_Sales_Revenue").Visible = False
.Shapes("Map_Chart_Sales_Units").Visible = True
.Shapes("Line_Chart_Sales_Units").Visible = True
End With
End Sub
Sub Display_Tab_Sales_Units()
With ActiveSheet
.Shapes("Revenue_Inactive").Visible = True
.Shapes("Revenue_Active").Visible = False
.Shapes("Units_Inactive").Visible = False
.Shapes("Units_Active").Visible = True
.Shapes("Map_Chart_Sales_Revenue").Visible = False
.Shapes("Line_Chart_Sales_Revenue").Visible = False
.Shapes("Map_Chart_Sales_Units").Visible = True
.Shapes("Line_Chart_Sales_Units").Visible = True
End With
End Sub

How to filter pivot table with multiple items?

I am trying to filter data from a pivot table. Why does the first setting work and the 2nd one does not? error is "unable to set the visible property in the PivotItem class"
should I be doing this any differently?
ultimately I want to filter based on a string and apply the correct settings to filter.
Sub Macro11()
'
ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand")
.PivotItems("BK").Visible = False
.PivotItems("CV").Visible = True
.PivotItems("CV R").Visible = True
.PivotItems("GC").Visible = False
.PivotItems("OS").Visible = False
.PivotItems("CL").Visible = False
.PivotItems("CL R").Visible = False
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand").CurrentPage = _
"(All)"
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand")
.PivotItems("Bk").Visible = False
.PivotItems("CV").Visible = False
.PivotItems("CV R").Visible = False
.PivotItems("GC").Visible = False
.PivotItems("OS").Visible = False
.PivotItems("CL").Visible = True
.PivotItems("CL R").Visible = True
End With
End Sub
Looks like this works...
Sub Macro11()
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand")
.ClearAllFilters
.EnableMultiplePageItems = True
.PivotItems("BK").Visible = False
.PivotItems("CV").Visible = True
.PivotItems("CV R").Visible = True
.PivotItems("GC").Visible = False
.PivotItems("OS").Visible = False
.PivotItems("CL").Visible = False
.PivotItems("CL R").Visible = False
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand")
.ClearAllFilters
.EnableMultiplePageItems = True
.PivotItems("Bk").Visible = False
.PivotItems("CV").Visible = False
.PivotItems("CV R").Visible = False
.PivotItems("GC").Visible = False
.PivotItems("OS").Visible = False
.PivotItems("CL").Visible = True
.PivotItems("CL R").Visible = True
End With
End Sub
Sub test()
Dim PI As PivotItem
Dim myArray() As Variant
Dim i As Integer
myArray = Array("BK", "GC", "OS", "CL", "CL R")
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand")
.ClearManualFilter
.EnableMultiplePageItems = True
For i = LBound(myArray) To UBound(myArray)
.PivotItems(myArray(i)).Visible = False
Next i
End With
End Sub
or you can use another approach
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Brand")
For Each PI In .PivotItems
If PI.Name <> "CV" Then PI.Visible = False
Next PI
End With
this is what ultimately worked for me:
For Each PT In ActiveSheet.PivotTables
PTname = PT.Name
Next
With ActiveSheet.PivotTables(PTname).PivotFields("Brand")
.ClearAllFilters
.EnableMultiplePageItems = True
For Each pvtitem In .PivotItems
If pvtitem.Name = "OS" Then
pvtitem.Visible = True
Else
pvtitem.Visible = False
End If
Next
End With

Run-time error 13 and after fix Run-time error 91

Hi I have problem with my program.
I´m trying to open UserForm2 from my UserForm1 but I need to Initialize some code for UserForm2 before show.
I used UserForm2.Show in my code and open it from UserForm1 by Show UserForm2 This Worked fine but when closing it gives me error 91.
I tried to remove UserForm2.Show but this caused UserForm2 didn´t load and gives me error 13.
Here is my code
Module1:
Option Explicit
Public ListName As String
UserForm1:
Private Sub CommandButton1_Click()
If CheckBox5.Value = False And CheckBox6.Value = False Then
MsgBox ("Nebyla zvolena operace.")
GoTo Ukoncit
End If
If CheckBox1.Value = False And CheckBox2.Value = False And CheckBox3.Value = False And CheckBox4.Value = False Then
MsgBox ("Nebyl zvolen list.")
GoTo Ukoncit
End If
If CheckBox5.Value = True Then
End If
If CheckBox6.Value = True Then
If CheckBox1.Value = True Then
ListName = "SAP_CZ"
ElseIf CheckBox2.Value = True Then
ListName = "SAP_CH"
ElseIf CheckBox3.Value = True Then
ListName = "Datab_1"
ElseIf CheckBox4.Value = True Then
ListName = "Datab_2"
End If
Show UserForm2 ' <------------- Here is Opening UserForm2
End If
Ukoncit:
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
CheckBox2.Enabled = False
CheckBox3.Enabled = False
CheckBox4.Enabled = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
If CheckBox1.Value = False Then
CheckBox2.Enabled = True
CheckBox3.Enabled = True
CheckBox4.Enabled = True
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
CheckBox1.Enabled = False
CheckBox3.Enabled = False
CheckBox4.Enabled = False
CheckBox1.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
If CheckBox2.Value = False Then
CheckBox1.Enabled = True
CheckBox3.Enabled = True
CheckBox4.Enabled = True
CheckBox1.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
End Sub
Private Sub CheckBox3_Click()
If CheckBox3.Value = True Then
CheckBox2.Enabled = False
CheckBox1.Enabled = False
CheckBox4.Enabled = False
CheckBox2.Value = False
CheckBox1.Value = False
CheckBox4.Value = False
End If
If CheckBox3.Value = False Then
CheckBox2.Enabled = True
CheckBox1.Enabled = True
CheckBox4.Enabled = True
CheckBox2.Value = False
CheckBox1.Value = False
CheckBox4.Value = False
End If
End Sub
Private Sub CheckBox4_Click()
If CheckBox4.Value = True Then
CheckBox2.Enabled = False
CheckBox3.Enabled = False
CheckBox1.Enabled = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox1.Value = False
End If
If CheckBox4.Value = False Then
CheckBox2.Enabled = True
CheckBox3.Enabled = True
CheckBox1.Enabled = True
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox1.Value = False
End If
End Sub
Private Sub CheckBox5_Click()
If CheckBox5.Value = True Then
CheckBox6.Enabled = False
CheckBox6.Value = False
End If
If CheckBox5.Value = False Then
CheckBox6.Enabled = True
CheckBox6.Value = False
End If
End Sub
Private Sub CheckBox6_Click()
If CheckBox6.Value = True Then
CheckBox5.Enabled = False
CheckBox5.Value = False
End If
If CheckBox6.Value = False Then
CheckBox5.Enabled = True
CheckBox5.Value = False
End If
End Sub
UserForm2 giving Error 91:
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim Label1String As String
Label1String = "Chcete opravdu smazat data z listu " & ListName
UserForm2.Label1.Caption = Label1String
UserForm2.Show
End Sub
UserForm2 giving Error 13:
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim Label1String As String
Label1String = "Chcete opravdu smazat data z listu " & ListName
UserForm2.Label1.Caption = Label1String
End Sub
This error is caused by Show UserForm2
It should be
UserForm2.Show
And you don't need to have this in your UserForm_Initialize sub
I edited this code by giving That code from Initialize to Activat, deleted UserForm1.Show and replace Unload Me with Hide
Now code is here in UserForm2:
Private Sub CommandButton1_Click()
Hide
End Sub
Private Sub UserForm_Activate()
Dim Label1String As String
Label1String = "Chcete opravdu smazat data z listu " & ListName
UserForm2.Label1.Caption = Label1String
End Sub
But still in UserForm1 row Show UserForm2 is giving runtime error 13.

Resources