1.VBA代ç ç¿»è¯
2.VBA 代ç ç¿»è¯
3.VBAç¨åºç¿»è¯
4.Excel VBA代码翻译
5.vba代ç ç¿»è¯ï¼è¶è¯¦ç»è¶å¥½
VBA代ç ç¿»è¯
Sub Macro1()
Dim Fso As Object,源译 a, i&, j&, n&, brr()
Application.ScreenUpdating = False 'å ³éå±å¹æ´æ°
Set Fso = CreateObject("Scripting.FileSystemObject") 'å建FSO对象
p = ThisWorkbook.Path & "\-3-1" 'å½åè·¯å¾ä¸çæ件夹
sFileType = "*.pdf" 'ç±»å为PDFæ件
Call GetFiles(p, sFileType, Fso) 'è°ç¨getfilesç¨åº
ReDim brr(1 To m, 1 To 4) 'å®ä¹äºç»´æ°ç»
[a1].CurrentRegion.Offset(1).ClearContents 'a1æç¨åºåæ´ä½åä¸æ¸ é¤å 容
With ActiveSheet '以ä¸æ¿æ´»ç表å è¿è¡
For i = 1 To m 'iä»1å°m循ç¯
a = Split(arr(i), "\") 'å°æ°ç»arr(i)ç¨\åå¼åå ¥æ°ç»a
n = 0
For j = UBound(a) - 3 To UBound(a) - 1 'jå¨æ°ç»aå çæåä¸ä¸ªæ°å¾ªç¯
n = n + 1 'nèªå ä¸æ¬¡
brr(i, n) = a(j) '为brrèµå¼
Next
brr(i, 4) = Replace(a(j), ".pdf", "") 'å é¤.pdf
.Hyperlinks.Add Anchor:=Cells(i + 1, 4), Address:=arr(i) '建ç«è¶ è¿æ¥
Next
End With
[a2].Resize(m, 4) = brr 'å°æ°ç»brrèµå°a2çæ©å±åºå
m = 0
Erase arr 'æ¸ é¤arr
Set Fso = Nothing 'æ¸ é¤fso
Application.ScreenUpdating = True 'å¼å¯å±å¹æ´æ°
End Sub
Private Sub GetFiles(ByVal sPath$, ByVal sFileType$, Fso As Object)
Dim Folder As Object
Dim SubFolder As Object
Dim File As Object
Set Folder = Fso.GetFolder(sPath)
For Each File In Folder.Files 'åéspathä¸çæ件
If File.Name Like sFileType Then 'å¦æ件ååsfiletypeç¸ä»¿
m = m + 1 'mèªå
ReDim Preserve arr(1 To m) 'éæ°å®ä¹æ°ç»arrï¼ä¿çåææ°æ®
arr(m) = sPath & "\" & File.Name '为æ°ç»çæ°å¢æ°æ®èµå¼
End If
Next
If Folder.SubFolders.Count > 0 Then 'å¦æåå¨åæ件夹
For Each SubFolder In Folder.SubFolders 'åéææåæ件夹
Call GetFiles(SubFolder.Path, sFileType, Fso) 'å次è¿è¡äºç¨åº
Next
End If
Set Folder = Nothing
Set File = Nothing
Set SubFolder = Nothing
End Sub
VBA 代ç ç¿»è¯
Sub test()
Dim oDic As Object
Dim i As Long
Dim Dsum
Dim Arr
Arr = Range("A1:C" & [A].End(xlUp).Row) 'æAï¼Bï¼Cåçæ°å¼è¯»å ¥æ°ç»
Set oDic = CreateObject("Scripting.Dictionary") 'å建åå ¸å¯¹è±¡ï¼åå ¸å¯¹è±¡çæ大ç¹ç¹å°±æ¯keyä¸éå¤ï¼å©ç¨è¿ä¸ªç¹ç¹è¿è¡åç±»æ±æ»
With oDic
For i = 1 To UBound(Arr) 'ä»æ°ç»arrç第ä¸è¡å¾ªç¯å°æå1è¡
oDic(Format(Arr(i, 1), "yy-m-d") & "@@" & Arr(i, 2)) = oDic(Format(Arr(i, 1), "yy-m-d") & "@@" & Arr(i, 2)) + Arr(i, 3) 'ææ°ç»çå两åé¾æ¥æ1个å符串ï¼éè¿åå ¸æå两åç¸åç第3åæ°æ®ç´¯è®¡
Next
End With
Dsum = oDic(Format("-8-5", "yy-m-d") & "@@" & "A") '"-8-5"è¿ä¸ªæ¯ä½ æ±åçæ¥æï¼"A"æ¯åç§°æ ¹æ®éè¦èªå·±è®¾ç½®ï¼æ¥æ¾ç¹å®æ¥æç¹å®å称çæ°éçåï¼
End Sub
VBAç¨åºç¿»è¯
Sub Macro1()
Dim rng As Range, c As Range, myPath$, myFile$, wb As Workbook, sh As Worksheet 'å®ä¹å¯¹è±¡,åå«å®ä¹çæ¯åå æ ¼,å°å,æ件以åå·¥ä½ç°¿!
Set sh = Sheets("1") '设置工ä½è¡¨1,å³SHEETS1
Set rng = sh.Range("A2:A" & sh.Range("A").End(xlUp).Row) 'SHEET1éä¸é空è¡
Application.ScreenUpdating = False 'å±å¹æ´æ°ä¸ºå
Application.DisplayAlerts = False 'åºåæ´æ°ä¸ºå
myPath = ThisWorkbook.Path & "\" 'å½åæ件ä¸è·¯å¾
myFile = Dir(myPath & "*.xls") 'å举EXCELæ件
Do While myFile <> " 'æ§è¡å¾ªç¯ä½
If myFile <> ThisWorkbook.Name Then 'æ¡ä»¶ä»¥ä¸ºæ件å为æ å
Set c = rng.Find(Split(myFile, ".")(0), , , xlWhole) 'FINDæ¥æ¾
If Not c Is Nothing Then
Set wb = GetObject(myPath & myFile)
With wb.Sheets(1)
.Range("e2").Resize(.Range("A").End(xlUp).Row - 1) = c.Offset(, 1).Value 'æ¾å°å 容åå°Eå
If d.Exists(c.Offset(, 1).Value) Then .Range("g2").Resize(.Range("A").End(xlUp).Row - 1) = d(c.Offset(, 1).Value) 'æ件é¿åº¦
End With
Windows(wb.Name).Visible = True
wb.SaveAs Filename:=ThisWorkbook.Path & "\" & c.Offset(, 1).Value & "_" & myFile 'ä¿åæ件
ActiveWorkbook.Close 'å ³éå·¥ä½ç°¿
End If
End If
myFile = Dir
Loop
Application.DisplayAlerts = True 'åºåæ´æ°
Application.ScreenUpdating = True 'å±å¹å¯å
MsgBox "å®æ"
End Sub
Excel VBA代码翻译
这代码出来是透视表或者 Sumifs 公式的效果, 直接一个公式就搞定的码翻源码资本市值事 还写这么复杂你这人 也是, 一毛不拔 还 找人翻译
Sub test()Dim arr,源译滴滴 app 源码 brr
Dim d As Object
Dim k%, i%, m%, str$, str1$
arr = Sheets("sheet1").Range("a1").CurrentRegion 'Sheet1数据存入数组
brr = Sheets("sheet2").Range("a2").CurrentRegion 'Sheet2 数据存入数组
Set d = CreateObject("scripting.dictionary") '创建字典对象
For k = 2 To UBound(arr)
str = arr(k, 1) & arr(k, 3) & arr(k, 2) 'sheet1 A列 C 列 B列每行内容合并
If Not d.exists(str) Then
d(str) = arr(k, 4) '这里写的是 废话多余
Else
d(str) = d(str) + arr(k, 4) '对A 列C 列B列 合并后的字符串 对应的第4列数字 求和
End If
Next k
For i = 2 To UBound(brr) 'Sheet2 的第2行开始 到最后一行
For m = 3 To UBound(brr, 2) 'sheet2的第3列 开始到最后一列,列数为m
str1 = brr(i,码翻邮箱api源码 1) & brr(i, 2) & brr(1, m) '合并内容为 A列+B列+ 第一行横向的m列
brr(i, m) = d(str1) '之前对应字符 求和的数据写入 数组对应位置
Next m
Next i
Sheets("sheet2").Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr'输出求和结果
End Sub
vba代ç ç¿»è¯ï¼è¶è¯¦ç»è¶å¥½
Private Sub Worksheet_Activate() å½æ¿æ´»å·¥ä½è¡¨æ¶æ§è¡
Application.ScreenUpdating = False 软件ççªå£åæ¢å·æ°
ActiveSheet.PivotTables("éè§è¡¨").PivotCache.Refresh å·æ°éè§è¡¨çæ°æ®
ActiveSheet.PivotTables("éè§è¡¨").PivotSelect "", xlDataAndLabel, True éæ©éè§è¡¨
Selection.RowHeight = '设置è¡é«
Rows("4:5").Select 'éä¸ç¬¬2è¡
Selection.EntireRow.Hidden = True 'éè
Range("a1").Select éæ©a1æ ¼
Application.ScreenUpdating = True å·æ°çªå£
End Sub