案例说明-根据条件值隐藏/取消隐藏

时间:2019-03-23 06:47:59

标签: excel vba

如果大小写为否,我试图隐藏一列。

我将其保存在工作表中,而不是模块中。

Private Sub Worksheet_Change(ByVal Target As Range)

    ActiveSheet.Activate

    If Not Application.Intersect(Range("C9"), Range(Target.Address)) Is     Nothing Then
        Select Case Target.Value
           Case Is = "Yes":
              Rows("10:10").EntireRow.Hidden = False
           Case Is = "No":
              Rows("10:10").EntireRow.Hidden = True
        End Select

    End If
End Sub

2 个答案:

答案 0 :(得分:0)

也许与区分大小写失败检查有关。 试试下面的代码,告诉我们是否可以解决问题:

class AuctionsTodayAdapter(val context: Context, val model: MutableList<Today>) :
    RecyclerView.Adapter<AuctionsTodayAdapter.MyHolder>() {

    private var newData: Long = 0

    init {
        for (items in model) {
            items.end.let {
                newData = items.end.toLong()
            }
        }
        //set the timer which will refresh the data every 1 second.
        object : CountDownTimer(newData, 1000) {
            override fun onFinish() {
                notifyDataSetChanged()
            }

            override fun onTick(p0: Long) {
                var i = 0
                val dataLength = model.size
                while (i < dataLength) {
                    val item = model[i]
                    item.end -= 1000
                    i++
                }
                notifyDataSetChanged()
            }
        }.start()
    }

    override fun onBindViewHolder(holder: MyHolder, position: Int) {
        var modelUse = model[position]
        //Img
        modelUse.image.let {
            Glide.with(context)
                .load(Constants.MAIN_BASE_URL + it)
                .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.RESOURCE))
                .into(holder.rowMAIN_img)
        }
        //Timer
        modelUse.end.let {
            if (modelUse.calculateEnd > 0) {
                holder.rowMAIN_timer.text = getDurationBreakdown(modelUse.end.toLong())
            } else {
                holder.rowMain_timer.text = "Finished"
            }
        }
    }

    private fun millToMins(milliSec: Long): String {
        var seconds = (milliSec / 1000).toInt()
        val hours = seconds / (60 * 60)
        val tempMint = seconds - hours * 60 * 60
        val minutes = tempMint / 60
        seconds = tempMint - minutes * 60

        return String.format("%02d", hours) + ":" + String.format(
            "%02d",
            minutes
        ) + ":" + String.format("%02d", seconds)
    }
}

答案 1 :(得分:0)

工作表计算事件

  • Workbook Download (Dropbox)
  • 如果公式更改了YesNo,则值更改时将不会触发Worksheet Change事件。
  • 将第一个代码复制到标准模块中,例如Module1(VBE >>插入>>模块)。
  • 将第二个代码复制到工作表模块中,例如Sheet1
  • 将第三个代码复制到 ThisWorkbook模块

Module1

Option Explicit

Public strYesNo As String

Sub YesNo(CellRange As Range, HideRow As Long)

    Const str1 As String = "Yes"
    Const str2 As String = "No"

    With CellRange
        If .Value <> strYesNo Then
            Select Case strYesNo
                Case str1
                    .Worksheet.Rows(HideRow).Hidden = False
                Case str2
                    .Worksheet.Rows(HideRow).Hidden = True
            End Select
            strYesNo = .Value
        End If
    End With

End Sub

Sub YesNo1()

    Const cSheet As Variant = "Sheet1"
    Const cRange As String = "C9"
    Const cCol As Long = 10

    YesNo ThisWorkbook.Worksheets(cSheet).Range(cRange), cCol

End Sub

Sheet1

Option Explicit

Private Sub Worksheet_Calculate()
    YesNo1
End Sub

此工作簿

Option Explicit

Private Sub Workbook_Open()
    YesNo1
End Sub