Dim r As Long, c As Long
With ws
If .AutoFilterMode Then .AutoFilterMode = False
r = .Cells.SpecialCells(xlLastCell).Row
c = Application.Max(52, .Cells.SpecialCells(xlLastCell).Column)
With .Range("A1", .Cells(r, c)) '.UsedRange
With .Columns(52)
If IsEmpty(.Cells(1, 1)) Then .Cells(1, 1) = "count"
With .Resize(.Rows.Count - 1, 1).Offset(1, 0)
.Cells.FormulaR1C1 = "=COUNTIF(C[-29], RC[-29])"
.Cells = .Cells.Value
End With
.AutoFilter field:=1, Criteria1:=">2"
With .Resize(.Rows.Count - 1, 1).Offset(1, 0)
If CBool(Application.Subtotal(103, .Cells)) Then
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If
End With
.AutoFilter
End With
.RemoveDuplicates Columns:=23, Header:=xlYes
End With
End With
输出应该是写在另一行上的每个变量,但我的代码似乎不起作用。有什么建议吗?
答案 0 :(得分:1)
返回的字符串缺少一些+
运算符,这是修复:
return var1 + '\n' + var2 + '\n' + var3
或者,使用格式化字符串:
return "{0}\n{1}\n{2}".format(var1, var2, var3)
甚至更多的Pythonic,将这些字符串加在一起:
return '\n'.join([var1, var2, var3])
现在字符串换行没问题,在调用函数时不要忘记显示它们:
print(function(a))
答案 1 :(得分:0)
在换行符之后,你错过了+
以连接所有字符串:
尝试:
return ((var1) + '\n' +
(var2) + '\n' +
(var3))
答案 2 :(得分:0)
好像你错过了代码中的'+'。它应该是:
def function(a):
var1 = 'stack'
var2 = 'flow'
var3 = 'over'
return ((var1) + '\n'+
(var2) + '\n'+
(var3))