简体   繁体   English

当Excel列由按钮过滤时,我的行应更新。 更新是关于将值插入可见的单元格

[英]When a excel column is filtered by a button, my rows should be updated. The update is about inserting values into visible cells

So basically what I want is that when I filter a column, that all visible cells get a formula. 所以基本上我想要的是,当我过滤列时,所有可见的单元格都会得到一个公式。 The =SUM formula to be exactly, but the first visible cell should get the value of 1. The SUM formula sums up the first visible cell above the active cell, in this case the first cell with a formula should be the cell under the cell with the value 1. =SUM公式正确,但第一个可见单元格的值应为SUM公式将活动单元格上方的第一个可见单元格求和,在这种情况下,具有公式的第一个单元格应为该单元格下方的单元格值为1。

The cell with the value of 1 is in the F column even as the cells with the formulas so for example: i filtered the cells F6,F9,F23. 与具有公式的单元格一样,值1的单元格也在F列中,例如:i过滤了单元格F6,F9,F23。 F6 should contain a 1, and F9 should contain =SUM(F6,E6) for F23 it must be =(F9,E9) . F6应该包含1,F9应该包含=SUM(F6,E6)对于F23,它必须是=(F9,E9)

This is my code so far: 到目前为止,这是我的代码:

Sub setValue()

Dim test As String
Dim rngCell As Excel.Range
Dim rngVisible As Excel.Range

gantCell = Sheets("Gantt Chart").Rows("5:1000").SpecialCells(xlCellTypeVisible).Row
calcCell = gantCell - 3
Lastrow = Cells.Find("*", [F5], , , xlByRows, xlPrevious).Row
Worksheets("Gantt Chart").Cells(gantCell, 6).Value = "1"
gantCellNext = Sheets("Gantt Chart").Rows("5:1000").SpecialCells(xlCellTypeVisible).Row
i = formCell
test = "F" & i
'MsgBox Lastrow
'MsgBox test
Sheets("Calculatie").Cells(calcCell, 2).Copy
For Each cell In Range(test).CurrentRegion.SpecialCells(xlCellTypeVisible)

Sheets("Gantt Chart").Range(test & ":F35").SpecialCells(xlCellTypeVisible).Formula = "=SUM(F" & activeCell.Row - 1 & "+" & "E" & activeCell.Row - 1 & ")"

Next

End Sub

Sorry if my English isn't that good, please help! 抱歉,如果我的英语不太好,请帮忙!

Thanks in advance. 提前致谢。

This may be oversimplifying your problem, but have you looked at the SUBTOTAL function and using the constant that ignores hidden values (in your case SUBTOTAL(109,range) )? 这可能会简化您的问题,但是您是否查看过SUBTOTAL函数并使用了忽略隐藏值的常量(在您的情况下为SUBTOTAL(109,range) )?

Take a look at the documentation on the SUBTOTAL function here - http://office.microsoft.com/en-us/excel-help/subtotal-function-HP010062463.aspx 在这里查看有关SUBTOTAL函数的文档-http: //office.microsoft.com/zh-cn/excel-help/subtotal-function-HP010062463.aspx

I've figured it out myself, heres the code. 我自己弄清楚了,这里是代码。

Sub setValue()

Dim test As String
Dim rCell As Range
Dim rRng As Range
Dim ling As String
Dim Rng As Range
Dim bol As Boolean

bol = False
GantCell = Sheets("Gantt Chart").Rows("5:1000").SpecialCells(xlCellTypeVisible).Row
calcCell = GantCell - 3
formCell = GantCell + 1
Lastrow = Cells.Find("*", [F5], , , xlByRows, xlPrevious).Row
Worksheets("Gantt Chart").Cells(GantCell, 6).Value = "1"
gantCellNext = Sheets("Gantt Chart").Rows("5:1000").SpecialCells(xlCellTypeVisible).Row
i = formCell
test = "F" & i
l = "F" & GantCell
Range(l).Activate
Set rRng = activeCell

For Each rCell In Range(l & ":F35").SpecialCells(xlCellTypeVisible)
ling = "F" & rCell.Row
'MsgBox ling
If bol = True Then
Set rRng = activeCell
rCell.Value = "=SUM(F" & rRng.Row & ":" & "E" & rRng.Row & ")"
Set rRng = Range(ling)
rRng.Select
ElseIf bol = False Then
Worksheets("Gantt Chart").Cells(GantCell, 6).Value = "1"
bol = True
End If
Next rCell


End Sub

Thanks everyone who tried to help me! 谢谢所有试图帮助我的人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM