返回列表 上一主題 發帖

[發問] 非常複雜選擇跟比對,當選擇H2時,可以得到 I2:L12 的結果?

學妹又來麻煩大家了
打開 EXCEL 檔有詳細說明喔
請帥哥/美女版主 帥哥/美女學長跟學姐
幫忙學妹完成
謝 ...
metrostar 發表於 2013-8-25 10:52
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.   Dim iCount1%, iCount2%, iI%
  3.   Dim lRow As Long, lRows As Long, lTRow As Long
  4.   Dim sMod1$, sMod2$
  5.   Dim bUse As Boolean
  6.   
  7.   With Target
  8. Application.EnableEvents = False
  9.     Range(.Offset(, 1), .Offset(10, 4)).Delete Shift:=xlShiftToLeft
  10.     If .Row = 2 And .Column = 8 Then '[H2]
  11.       With .Parent
  12.         lRow = .Cells(Rows.Count, 1).End(xlUp).Row
  13.         lRows = .Cells(Rows.Count, 5).End(xlUp).Row
  14.         If lRow > lRows Then lRows = lRow
  15.         lTRow = 0
  16.         bUse = False
  17.         For lRow = 2 To lRows
  18.           If Trim(.Cells(lRow, 1).Text) = Trim(Target) Then
  19.             Target.Offset(lTRow, 1) = .Cells(lRow, 2)
  20.             Target.Offset(lTRow, 2) = .Cells(lRow, 3)
  21.             bUse = True
  22.           End If
  23.          
  24.           If Trim(.Cells(lRow, 5).Text) = Trim(Target) Then
  25.             Target.Offset(lTRow, 3) = .Cells(lRow, 4)
  26.             Target.Offset(lTRow, 4) = .Cells(lRow, 6)
  27.             bUse = True
  28.           End If
  29.           If bUse Then lTRow = lTRow + 1
  30.         Next lRow
  31.       End With
  32.     End If
  33.     With Range(.Offset(, 1), .Offset(10, 4))
  34.       .Interior.ColorIndex = 39
  35.       .VerticalAlignment = xlCenter
  36.       .HorizontalAlignment = xlCenter
  37.       .Borders.LineStyle = xlContinuous
  38.     End With
  39. Application.EnableEvents = True
  40.   End With
  41. End Sub
複製代碼
metrostar201308-a.zip (11.25 KB)

TOP

        靜思自在 : 唯其尊重自己的人,才更勇於縮小自己。
返回列表 上一主題