- ©«¤l
- 2035
- ¥DÃD
- 24
- ºëµØ
- 0
- ¿n¤À
- 2031
- ÂI¦W
- 0
- §@·~¨t²Î
- Win7
- ³nÅ骩¥»
- Office2010
- ¾\ŪÅv
- 100
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-3-22
- ³Ì«áµn¿ý
- 2024-2-1
|
¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-8-6 11:52 ½s¿è
¦^´_ 12# VBALearner - Option Explicit
- Option Base 1
- Sub ½Õ¾ãÀx¦s®æ¤j¤p()
- Dim cts As Integer
-
- For cts = 1 To Sheets.Count
- With Sheets(cts)
- .Activate
- .Columns.ColumnWidth = 10
- .Rows.RowHeight = 15
- End With
- Next
- End Sub
- Sub §å¶q¶×¤J¶R½æ¶W»P»ù®æ()
- Call ¤W¥«¤WÂd¥æ©ö("¤W¥«¥~¸ê", "¤W¥«§ë«H", 4, 7, "201*") ' §å¶q¶×¤J¶R½æ¶W
- Call ¤W¥«¤WÂd¥æ©ö("¤WÂd¥~¸ê", "¤WÂd§ë«H", 4, 7, "BIG*") ' §å¶q¶×¤J»ù®æ
- Call ¤W¥«¤WÂd¥æ©ö("¤W¥«¦¬½L»ù", "", 8, 0, "A112201*") ' §ó·s¶R½æ¶W
- Call ¤W¥«¤WÂd¥æ©ö("¤WÂd¦¬½L»ù", "", 2, 0, "SQUOTE*") ' §ó·s»ù®æ
- Beep
- End Sub
- Sub ¤W¥«¤WÂd¥æ©ö(tbl As String, tbl2 As String, pos1 As Integer, pos2 As Integer, typ As String, Optional auto As Boolean = False)
- Dim myFile As String, myDate As String
- Dim rng As Range, stkNo As Variant
- Dim wb As Workbook
- Dim cts As Long, xs As Long
-
- Application.ScreenUpdating = False
- xs = Sheets(tbl).Range("A" & Rows.Count).End(xlUp).Row
- ReDim tget2(xs - 1) As Long
- If pos2 > 0 Then
- ReDim tget3(xs) As Long
- End If
- stkNo = Application.Transpose(Range(Sheets(tbl).Range("A2"), Sheets(tbl).[A2].End(xlDown)))
-
- myFile = Dir("C:\¤T¤jªk¤H§ó·s°Ï\" & typ)
- Do While myFile <> ""
- Workbooks.Open "C:\¤T¤jªk¤H§ó·s°Ï\" & myFile
- Select Case typ
- Case "201*" ' (20160802_2by_issue.csv)
- myDate = Left(myFile, 8)
- Case "BIG*" ' (BIGD_1050802.csv)
- myDate = Mid(myFile, 6, 7): myDate = CStr((Val(Left(myDate, 3)) + 1911)) + Mid(myDate, 4, 4)
- Case "A112201*" ' (A11220160802ALL.csv)
- myDate = Mid(myFile, 5, 8)
- Case "SQUOTE*" ' (SQUOTE_AL_1050802.csv)
- myDate = Mid(myFile, 11, 7): myDate = CStr((Val(Left(myDate, 3)) + 1911)) + Mid(myDate, 4, 4)
- End Select
-
- myDate = Left(myDate, 4) + "/" + Mid(myDate, 5, 2) + "/" + Right(myDate, 2)
-
- myFile = Dir '²Ä¤G¦¸½Õ¥ÎDir¨ç¼Æ¦Ó¤£±a¥ô¦ó°Ñ¼Æ¡A«h·|ªð¦^¦Ü¦P¤@¥Ø¿ý¤Uªº¤U¤@Ó¤å¥ó
-
- Set wb = ActiveWorkbook
- With Sheets(1)
- For cts = 1 To xs - 1
- Set rng = .Range("A:A").Find(stkNo(cts))
- If Not rng Is Nothing Then
- tget2(cts) = IIf(IsNumeric(rng.Offset(0, pos1).Value), rng.Offset(0, pos1).Value, 0) ' (0, 8)
- If pos2 > 0 Then tget3(cts) = IIf(IsNumeric(rng.Offset(0, pos2).Value), rng.Offset(0, pos2).Value, 0) ' (0, 7)
- Else
- tget2(cts) = 0
- If pos2 > 0 Then tget3(cts) = 0
- End If
- Next
- End With
- wb.Close SaveChanges:=False
-
- With Sheets(tbl)
- .Activate
- Set rng = Range(.[A1], .[A1].End(xlToRight)) ' ±q A Äæ¦Ü³Ì¥kÄæ¦ì½d³ò
- Set rng = rng.Find(CDate(myDate), LookIn:=xlValues, LookAt:=xlWhole)
- If rng Is Nothing Then
- .Range("C:C").Insert
- Set rng = .[C1]
- rng.Value = myDate
- End If
- ' Range(.Range("C2"), .Range("C" & .[A2].End(xlDown).Row)) = Application.Transpose(tget2)
- Range(rng.Offset(1), .Range(Chr(64 + rng.Column) & .[A2].End(xlDown).Row)) = Application.Transpose(tget2)
- End With
-
- If tbl2 <> "" Then
- With Sheets(tbl2)
- .Activate
- Set rng = Range(.[A1], .[A1].End(xlToRight)) ' ±q A Äæ¦Ü³Ì¥kÄæ¦ì½d³ò
- Set rng = rng.Find(CDate(myDate), LookIn:=xlValues, LookAt:=xlWhole)
- If rng Is Nothing Then
- .Range("C:C").Insert
- Set rng = .[C1]
- rng.Value = myDate
- End If
- ' Range(.Range("C2"), .Range("C" & .[A2].End(xlDown).Row)) = Application.Transpose(tget3)
- Range(rng.Offset(1), .Range(Chr(64 + rng.Column) & .[A2].End(xlDown).Row)) = Application.Transpose(tget3)
- End With
- End If
- Loop
-
- Application.ScreenUpdating = True
- End Sub
½Æ»s¥N½X |
|