我希望VBA从范围(U2:VN2)中选择最大值并将值粘贴到范围VO2中 然后自动填充列VO,因此列VO将显示每行向下到最后一行的最大值。
我尝试了以下
Sub MaxValueAutofill()
Dim r As Excel.Range
Dim rX As Excel.Range
Dim lastRow As Long
Dim lngMax As Double
Set r = Range("U2:VN2")
lngMax = Application.Max(r)
Set rX = r.Find(What:=lngMax, After:=Range("U2"), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False)
If Not rX Is Nothing Then
Application.Goto rX, Scroll:=True
End If
Selection.Copy
Range("VO2").Select
ActiveSheet.Paste
lastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("VO2").AutoFill Destination:=Range("VO2:VO" & lastRow)
End Sub
非常感谢任何帮助。
答案 0 :(得分:0)
这应该足够了:
table = 'myTable'
_SQL = """SHOW TABLES"""
cursor.execute(_SQL)
results = cursor.fetchall()
print('All existing tables:', results) # Returned as a list of tuples
results_list = [item[0] for item in results] # Conversion to list of str
if table in results_list:
print(table, 'was found!')
else:
print(table, 'was NOT found!')
答案 1 :(得分:0)
根据问题陈述&#34;每行的最大值&#34;,听起来好像你只想将第2行的最大值复制到列VO的每一行,所以自动填充<列中的em> value 一直不合适。你实际上需要自动填充&#34; Max&#34; 公式一直向下,然后转换为值。
Sub MaxValueAutofill()
With ActiveSheet
With .Range("VO2:VO" & .Range("A" & .Rows.Count).End(xlUp).Row)
.Formula = "=MAX(U2:VN2)"
.Value = .Value
End With
End With
End Sub