VBA 检查表名称是否存在

Function ExistSheetName(name As String) Dim sht As Worksheet For Each sht In Worksheets If sht.name = name Then ExistSheetName = True Exit Function End If Next ExistSheetName = False End Function

Excel VBA 添加新工作簿

' 创建工作簿, Dim newWb As Workbook '或在另一个应用实例(进程)中创建 Dim newWb as appExcel.Workbook ? Set newWb = Workbooks.Add 如果要给工作簿命名,只有在保存时,指定文件名。 wb.SaveAs Filename:="NewWB"

VBA 查找值所在的列号

Function FindColOfValue(ws As Worksheet, val As Variant, rowNum As Long, startCol As Long) Dim i As Long With ws For i = startCol To .Range(.Cells(startCol, rowNum), .Cells(startCol, rowNum)).CurrentRegion.Columns.Count() If .Cells(rowNum, i).Value = val Then FindColOfValue = i Exit Function End If Next End With FindColOfValue = -1 End Function

VBA 查找值所在的行号

Function FindRowOfValue(ws As Worksheet, val As Variant, colNum As Long, startRow As Long) Dim r As Long With ws For r = startRow To .Range(.Cells(startRow, colNum), .Cells(startRow, colNum)).CurrentRegion.Rows.Count() If .Cells(r, colNum).Value = val Then FindRowOfValue = r Exit Function End If Next End With End Function

Python 字典排序

Sort a dictionary by value 依据字典的值进行排序 newDict = {k: v for k, v in sorted(x.items(), key=lambda item: item[1])} import operator # 示例字典 d = {'a': 3, 'e': 4, 'b': 2, 'c': 5, 'd': 1} # 按 key 排序 def dict_sort_by_key(d: dict): sorted_d = sorted(d.items(), key=operator.itemgetter(0)) return dict(sorted_d) # 按 value 排序 def dict_sort_by_val(d: dict): # sorted_dic