標題:
[發問]
非常複雜選擇跟比對,當選擇H2時,可以得到 I2:L12 的結果?
[打印本頁]
作者:
metrostar
時間:
2013-8-25 10:52
標題:
非常複雜選擇跟比對,當選擇H2時,可以得到 I2:L12 的結果?
學妹又來麻煩大家了
打開 EXCEL 檔有詳細說明喔
請帥哥/美女版主 帥哥/美女學長跟學姐
幫忙學妹完成
謝謝了
作者:
luhpro
時間:
2013-8-27 00:21
學妹又來麻煩大家了
打開 EXCEL 檔有詳細說明喔
請帥哥/美女版主 帥哥/美女學長跟學姐
幫忙學妹完成
謝 ...
metrostar 發表於 2013-8-25 10:52
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iCount1%, iCount2%, iI%
Dim lRow As Long, lRows As Long, lTRow As Long
Dim sMod1$, sMod2$
Dim bUse As Boolean
With Target
Application.EnableEvents = False
Range(.Offset(, 1), .Offset(10, 4)).Delete Shift:=xlShiftToLeft
If .Row = 2 And .Column = 8 Then '[H2]
With .Parent
lRow = .Cells(Rows.Count, 1).End(xlUp).Row
lRows = .Cells(Rows.Count, 5).End(xlUp).Row
If lRow > lRows Then lRows = lRow
lTRow = 0
bUse = False
For lRow = 2 To lRows
If Trim(.Cells(lRow, 1).Text) = Trim(Target) Then
Target.Offset(lTRow, 1) = .Cells(lRow, 2)
Target.Offset(lTRow, 2) = .Cells(lRow, 3)
bUse = True
End If
If Trim(.Cells(lRow, 5).Text) = Trim(Target) Then
Target.Offset(lTRow, 3) = .Cells(lRow, 4)
Target.Offset(lTRow, 4) = .Cells(lRow, 6)
bUse = True
End If
If bUse Then lTRow = lTRow + 1
Next lRow
End With
End If
With Range(.Offset(, 1), .Offset(10, 4))
.Interior.ColorIndex = 39
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
End With
Application.EnableEvents = True
End With
End Sub
複製代碼
[attach]15862[/attach]
作者:
Hsieh
時間:
2013-8-29 15:13
回復
1#
metrostar
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, C As Range, Ar()
If Intersect(Target, [H2]) Is Nothing Then Exit Sub
Set A = [E:E].Find(Target, lookat:=xlWhole)
If A Is Nothing Then Exit Sub
ReDim Preserve Ar(s)
Ar(s) = Array([B1].Value, [C1].Value, [D1].Value, [F1].Value)
s = s + 1
For Each C In A.MergeArea
ReDim Preserve Ar(s)
Ar(s) = Array(C.Offset(, -3).MergeArea(1).Value, C.Offset(, -2).MergeArea(1).Value, C.Offset(, -1).MergeArea(1).Value, C.Offset(, 1).MergeArea(1).Value)
s = s + 1
Next
Application.EnableEvents = False
[I:L] = ""
With Range("I1")
.Resize(s, 4) = Application.Transpose(Application.Transpose(Ar))
.CurrentRegion.Offset(, 1).Sort key1:=.Range("A1"), Header:=xlYes
End With
Application.EnableEvents = True
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)