- ©«¤l
- 552
- ¥DÃD
- 3
- ºëµØ
- 0
- ¿n¤À
- 578
- ÂI¦W
- 0
- §@·~¨t²Î
- win7
- ³nÅ骩¥»
- office 2010
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2015-2-8
- ³Ì«áµn¿ý
- 2024-7-9
|
¦^´_ 14# mark761222
¦³2ºØ¤è¦¡¡A½Ð¦Û¦æ´ú¸Õ¡A¿ï¾Ü¦Û¤vªº»Ý¨D¡A¤@ºØ¬°¦³¨ç¼ÆªºÀx¦s®æ´N¼g¤J¨ç¼Æ¡A¦ýŲ©ó¦³¥i¯à°µ·L½Õ¬G¦³²Ä¤GºØ¤è¦¡¡A¸õ¹L¦³¨ç¼ÆªºÀx¦s®æ- Option Explicit
- Sub Ex() '¤è¦¡1¬°¼g¤J¨ç¼Æ
- Dim xlPath As Variant, xlFile As Variant
- Dim Rng As Range, Rn As Range, Ran As Range, ch As Range
- Dim myCol As Integer, myRow As Integer, k As Integer
- Dim xlRo As Integer
- Dim arr
- xlPath = ThisWorkbook.Path & "\" 'Ū¨ú¥»µ{¦¡Àɪº¸ô®|
- xlFile = "¨C¤é§ó·s±µ¦¬.xlsx" 'Ū¨ú¥»µ{¦¡ÀɦWºÙ
- With ThisWorkbook.Sheets("¤u§@ªí1")
- myCol = .Cells(1, Columns.Count).End(xlToLeft).Column '¬d¸ß¤u§@ªí1ªº³Ì«á¤@Äæ¦ì¸m
- myRow = .Cells(Rows.Count, 1).End(xlUp).Row '¬d¸ß¤u§@ªí1ªº³Ì«á¤@¦C¦ì¸m
- For Each Rng In .Range("A2", .Cells(myRow, 1)) '¦¹°j°é°µ ¦³¸ê®ÆRange¦ì¸mªºÁp¶° Union
- If Rng <> "" Then
- k = k + 1
- If k = 1 Then
- Set Rn = Rng
- Else
- Set Rn = Union(Rn, Rng)
- End If
- End If
- Next
- End With
- Workbooks.Open (xlPath & xlFile) '¥´¶}"¨C¤é§ó·s±µ¦¬.xlsx"¬¡¶Ã¯
- For Each Ran In Rn
- With Workbooks(xlFile).Sheets(Ran.Value)
- Set ch = .Columns(1).Find(Ran.Offset(, 1), LookAt:=xlWhole, SearchDirection:=2)
- 'Àˬd¤é´Á¬O§_¦³«½Æ¡A·íchÅܼƬ°Nothing®É¡A«hµLµo²{«½Æ¤é´Á¡A§_«hÂ÷¶}³o¤@¦¸ªº¸ê®ÆÀx¦s¡A¨Ã°õ¦æ¤U¤@Ó°j°é
- If Not ch Is Nothing Then MsgBox Ran & "¤u§@ªí¤¤ªº" & ch & "¸ê®Æ¤w¦s¦b¡A¤£·|Àx¦s¸ê®Æ": Set ch = Nothing: GoTo 10
- arr = Ran.Offset(, 1).Resize(, myCol - 1)
- ''''§â¤½¦¡´À´«°}¦C¤¤ªºÈ'''
- arr(1, 5) = "=SUM(RC[5]:RC[13])"
- arr(1, 6) = "=1-RC[-1]/RC[-2]"
- arr(1, 8) = "=SUM(RC[12]:RC[18])"
- arr(1, 9) = "=1-RC[-1]/RC[-2]"
- arr(1, 29) = "=SUM(RC[5]:RC[10])"
- arr(1, 30) = "=1-RC[-1]/RC[-2]"
- arr(1, 48) = "=SUM(RC[2]:RC[11])"
- arr(1, 49) = "=1-RC[-1]/RC[-2]"
- ''''
- xlRo = .Cells(Rows.Count, 1).End(xlUp).Row + 1
- .Cells(xlRo, 1).Resize(, UBound(arr, 2)) = arr '¼g¤J¸ê®Æ
- End With
- 10:
- Next
- Workbooks(xlFile).Close True 'Ãö³¬"¨C¤é§ó·s±µ¦¬.xlsx"¬¡¶Ã¯
- End Sub
- Sub Ex1() '¤£¼g¤J¨ç¼Æ¸õ¹L¦³¨ç¼ÆªºÀx¦s®æ
- Dim xlPath As Variant, xlFile As Variant
- Dim Rng As Range, Rn As Range, Ran As Range, ch As Range
- Dim myCol As Integer, myRow As Integer, k As Integer, I As Integer
- Dim xlRo As Integer
- Dim arr
- xlPath = ThisWorkbook.Path & "\" 'Ū¨ú¥»µ{¦¡Àɪº¸ô®|
- xlFile = "¨C¤é§ó·s±µ¦¬.xlsx" 'Ū¨ú¥»µ{¦¡ÀɦWºÙ
- With ThisWorkbook.Sheets("¤u§@ªí1")
- myCol = .Cells(1, Columns.Count).End(xlToLeft).Column '¬d¸ß¤u§@ªí1ªº³Ì«á¤@Äæ¦ì¸m
- myRow = .Cells(Rows.Count, 1).End(xlUp).Row '¬d¸ß¤u§@ªí1ªº³Ì«á¤@¦C¦ì¸m
- For Each Rng In .Range("A2", .Cells(myRow, 1)) '¦¹°j°é°µ ¦³¸ê®ÆRange¦ì¸mªºÁp¶° Union
- If Rng <> "" Then
- k = k + 1
- If k = 1 Then
- Set Rn = Rng
- Else
- Set Rn = Union(Rn, Rng)
- End If
- End If
- Next
- End With
- Workbooks.Open (xlPath & xlFile) '¥´¶}"¨C¤é§ó·s±µ¦¬.xlsx"¬¡¶Ã¯
- For Each Ran In Rn
- With Workbooks(xlFile).Sheets(Ran.Value)
- Set ch = .Columns(1).Find(Ran.Offset(, 1), LookAt:=xlWhole, SearchDirection:=2)
- 'Àˬd¤é´Á¬O§_¦³«½Æ¡A·íchÅܼƬ°Nothing®É¡A«hµLµo²{«½Æ¤é´Á¡A§_«hÂ÷¶}³o¤@¦¸ªº¸ê®ÆÀx¦s¡A¨Ã°õ¦æ¤U¤@Ó°j°é
- If Not ch Is Nothing Then MsgBox Ran & "¤u§@ªí¤¤ªº" & ch & "¸ê®Æ¤w¦s¦b¡A¤£·|Àx¦s¸ê®Æ": Set ch = Nothing: GoTo 20
- xlRo = .Cells(Rows.Count, 1).End(xlUp).Row + 1
- For I = 1 To myCol - 1
- If I = 5 Or I = 6 Or I = 8 Or I = 9 Or I = 29 Or I = 30 Or I = 48 Or I = 49 Then GoTo 10 '¤£¼g¤J¨ç¼Æ¸õ¹L¦³¨ç¼ÆªºÀx¦s®æ
- .Cells(xlRo, I) = Ran.Offset(, I)
- 10:
- Next
- End With
- 20:
- Next
- Workbooks(xlFile).Close True 'Ãö³¬"¨C¤é§ó·s±µ¦¬.xlsx"¬¡¶Ã¯
- End Sub
½Æ»s¥N½X |
|