01
列数字转字母
ConvertToLetter = Split(Cells(1, iCol).Address(1, 0), "$")(0)
02
选择性粘贴
ActiveSheet.Range("F2:" & myChar & ActiveSheet.UsedRange.Rows.Count).Select Selection.Copy ActiveSheet.Range("F2").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False
03
查找替换
ActiveSheet.Cells.Replace What:="@", Replacement:="", LookAt:=xlPart, SearchOrder:= _ xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _ FormulaVersion:=xlReplaceFormula2
05
日期格式化及年龄计算
Format(Mid(ActiveSheet.Cells(i, 3).Value, 7, 8), "0000-00-00") DateDiff("yyyy", iyear, Date)
06
多条件vlookup公式
Sheets("转换后数据").Cells(2, k).Value = "=IFERROR(VLOOKUP(A2&E2&$" & myChar & "$1,IF({1,0},源数据!A:A" & Chr(38) & "源数据!C:C " & Chr(38) & "源数据!D:D,源数据!E:E),2,FALSE)," & Chr(34) & Chr(34) & ")"
07
for……each的用法
For Each outItem In outItems myChar = ConvertToLetter(k) Sheets("转换后数据").Cells(1, k).Value = outItem k = k + 1 Next
08
清除内容和格式
Sheets("转换后数据").Range("A:AZ").ClearContents Sheets("转换后数据").Range("A:AZ").ClearFormats
09
把listbox的内容放置到数组
For i = 0 To UserForm1.ListBox2.ListCount - 1 outItems(i) = UserForm1.ListBox2.List(i) Next i
10
往listbox中添加内容
mylist=array("1","2","3") For i = 1 To UBound(mylist) UserForm1.ListBox1.AddItem mylist(i) Next i
11
清除选中的listbox内容
For i = 0 To ListBox2.ListCount - 1 If ListBox2.Selected(i) = True Then ListBox2.RemoveItem (i) ListBox2.Selected(i) = False End If Next i
12
生成不重复随机数
Randomize '初始化随机因子 For i = startNum To endNum C.Add i Next For i = 1 To endNum - startNum + 1 Randomize (Time) k = Int((endNum - startNum + 2 - i) * Rnd + startNum) Rt = C.Item(k) C.Remove (k) Next GetRndNum = Rt
13
字典去重
'定义字典 Set Dic = CreateObject("Scripting.dictionary") a11 = Range(ColumnNo & startRow & ":" & ColumnNo & endRow).Value For i = 1 To UBound(a11) If a11(i, 1) <> "" Then Dic(a11(i, 1)) = "" End If Next result = Dic.Keys 'Range("D1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(result) duplicate = Application.WorksheetFunction.Transpose(result)
14
按行/列输出数组
'输出1行 Sheets("Sheet1").Range("A" & Csize).Resize(1, Dic.Count) = result '转置 输出Csize行 Sheets("Sheet1").Range("A" & Csize).Resize(Dic.Count,Csize) = Application.WorksheetFunction.Transpose(result)
©️公众号:思考者文刀
- 上一篇: VBA编程常见场景的十种常用方法
- 下一篇: VBA编程常见场景的二十八种常用方法
评论
游客
回复帖子好乱!http://3rt.xzsjesc.cn
游客
回复观点鲜明,立场坚定,作者态度明确。http://p8op1.xzsjesc.cn
游客
回复楼主人气很旺!http://9n23h.zhujibus.com
游客
回复这么版块的帖子越来越有深度了!http://q5v.yonghengtang.cn
游客
回复楼主看起来很有学问!http://www.chifengzj.com
游客
回复今天上网不回帖,回帖就回精华帖!http://www.uipsh.com
游客
回复楼主看起来很有学问!http://rhkl.tjjixi.com
游客
回复楼上的很有激情啊!http://m.snjunying.com