the macro does not work with the formula in the cell

Beleric3380

New Member
Joined
Aug 10, 2022
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hello!
I have a macro that expands or collapses rows depending on the value. If we fill in the values ourselves or from the list, then everything works.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 2 Then

On Error Resume Next

If Target = "Yes" Then

Rows(Target.Row + 1).ShowDetail = Target = "Yes"

ElseIf Target = "No" Then

Rows(Target.Row + 1).ShowDetail = Target = "Yes"

End If

On Error GoTo 0

End If

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Welcome to the MrExcel board!

That is because the Worksheet_Change event is not triggered by a formula calculation.

What is the actual formula in column 2? (Say for row 3)
 
Upvote 0
Hello! Adding a picture. B3 Sheet1 = B10 Sheet2 and it's not working. B9 sheet1 is a list and all working good
 

Attachments

  • group.png
    group.png
    27.9 KB · Views: 4
Upvote 0
Thanks. The question then becomes: Is cell B10 in Sheet2 also a formula?
If it is not a formula, try the Worksheet_Change event in the Sheet2 module.
This is only set for one set of rows in Sheet1 but is testing to see if it does what you want.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address = "$B$10" Then
    Sheets("Sheet1").Rows(4).ShowDetail = Target.Value = "Yes"
  End If
End Sub
 
Upvote 0
Thanks. The question then becomes: Is cell B10 in Sheet2 also a formula?
If it is not a formula, try the Worksheet_Change event in the Sheet2 module.
This is only set for one set of rows in Sheet1 but is testing to see if it does what you want.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address = "$B$10" Then
    Sheets("Sheet1").Rows(4).ShowDetail = Target.Value = "Yes"
  End If
End Sub
B10 — это не формула. все работает. Спасибо. как сделать чтобы разворачивание было на несколько слов (Да, Да_1, Да_2...) пробовал так

[КОД=vba]
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$10" Then
Sheets("FARA OPP").Rows(50).ShowDetail = Target.Value = "Yes"
ElseIf Target.Address = "$B$10" Then
Sheets("FARA OPP").Rows(50).ShowDetail = Target.Value = "Yes_1"
End If
End Sub
[/КОД]
 
Upvote 0
Please post in English only in this forum.
 
Upvote 0
Please post in English only in this forum.
B10 is not a formula. everything works. Thanks. how to make the unfolding be a few words (Yes, Yes_1, Yes_2...) I tried it like this
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$10" Then
Sheets("FARA OPP").Rows(50).ShowDetail = Target.Value = "Yes"
ElseIf Target.Address = "$B$10" Then
Sheets("FARA OPP").Rows(50).ShowDetail = Target.Value = "Yes_1"
End If
End Sub
 
Upvote 0
how to make the unfolding be a few words (Yes, Yes_1, Yes_2...)
Try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address = "$B$10" Then
    Select Case Target.Value
      Case "Yes", "Yes_1", "Yes_2"
        Sheets("FARA OPP").Rows(50).ShowDetail = True
      Case Else
        Sheets("FARA OPP").Rows(50).ShowDetail = False
    End Select
  End If
End Sub
 
Upvote 0
Solution
Another way would be

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address = "$B$10" Then Sheets("FARA OPP").Rows(50).ShowDetail = InStr(1, "|Yes|Yes_1|Yes_2|", "|" & Target.Value & "|")
End Sub
 
Upvote 0
Try
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Address = "$B$10" Then
    Select Case Target.Value
      Case "Yes", "Yes_1", "Yes_2"
        Sheets("FARA OPP").Rows(50).ShowDetail = True
      Case Else
        Sheets("FARA OPP").Rows(50).ShowDetail = False
    End Select
  End If
End Sub
Thank you! It's working.
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

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