简体   繁体   English

如何在搜索范围内搜索?

[英]How do I search within a searched range?

I have the following data, and i want to map it into an excel sheet with a particular format. 我有以下数据,我想将其映射到具有特定格式的Excel工作表中。 I need to extract the node name ie. 我需要提取节点名称,即。 "BLRTRC1" , "BSC23" , "BSC41" (there can be multiple occurrences of a single node with different alarm conditions). "BLRTRC1""BSC23""BSC41" (单个节点可能多次出现具有不同警报条件的事件)。

First I have to search for "BLRTRC1" , now I want to search all the alarm names that can be there like "SYNCHRONOUS DIGITAL PATH FAULT SUPERVISION", "DIGITAL PATH QUALITY SUPERVISION" etc within its range ie. 首先,我必须搜索"BLRTRC1" ,现在我要搜索其范围内的所有警报名称,例如“同步数字路径故障监控”,“数字路径质量监控”等。 up until the next node name does not show up (like in this case "BSC23" shows up after 3 occurrences of "BLRTRC1" ) 直到下一个节点名称不显示为止(例如在这种情况下,如果出现3次"BSC23"显示"BLRTRC1"

Then print the node name with the alarm name and the alarm statistics like 然后打印带有警报名称和警报统计信息的节点名称,例如

"SDIP     STATE     LAYER    K   L  M  FAULT  INFO    DATE    TIME
 8ETM2    TRAFLIM   VC15-2   32  1  1  UNEQ           130226  030244"  

Similarly I have to do this for all the nodes. 同样,我必须对所有节点执行此操作。 I have been stuck on this for over a week now, just cannot seem to get it, please help. 我已经在这个问题上停留了一个多星期,但似乎无法理解,请帮助。

Here is the sample text I want to edit. 这是我要编辑的示例文本。

PS. PS。 I have already imported this text into the excel sheet in "A:A" 我已经将此文本导入“ A:A”中的excel工作表中

A1/APT "BLRTRC1\02\G12" 007 130226   0302      
SYNCHRONOUS DIGITAL PATH FAULT SUPERVISION

SDIP     STATE     LAYER    K  L  M  FAULT  INFO    DATE    TIME
8ETM2    TRAFLIM   VC15-2   32  1  1  UNEQ           130226  030244

TYPE  PL/TTI                                   ERDIINFO


A1/APT "BLRTRC1\02\G12" 007 130226   0302      
SYNCHRONOUS DIGITAL PATH FAULT SUPERVISION

SDIP     STATE     LAYER    K  L  M  FAULT  INFO    DATE    TIME
7ETM2    TRAFLIM   VC12-2   3  1  1  UNEQ           130226  030244

TYPE  PL/TTI                                   ERDIINFO


A3/APT "BLRTRC1\02\G12" 009 130226   0302      
DIGITAL PATH QUALITY SUPERVISION

SDIP     STATE     LAYER    K  L  M  FAULT  INFO    DATE    TIME
7ETM2    TRAFLIM   VC12-8   3  3  1  UNEQ           130226  030244

TYPE  PL/TTI                                   ERDIINFO


A3/APT "BBSC23/G12A/CPA" 021 130521   1130      
DIGITAL PATH QUALITY SUPERVISION

SES
DIP      DIPPART  SESL2  QSV    SECTION  DATE    TIME
42MNPBS           1      1               130521  113000

TYPE  PL/TTI                                   ERDIINFO

A2/APT "BSC41\\CPA02\\G" 985 130521   1204      
DIGITAL PATH FAULT SUPERVISION

DIP      DIPEND   FAULT     SECTION   HG  DATE    TIME
BL2397            RDI                     130521  120407

and this is the type of output i require with the use of a macro 这是我需要使用宏的输出类型

nodename        Alarm name                                  alarmlevel
BLRTRC1 SYNCHRONOUS DIGITAL PATH FAULT SUPERVISION  SDIP     STATE     LAYER    K  L  M  FAULT  INFO    DATE    TIME
                                                    8ETM2    TRAFLIM   VC15-2   32  1  1  UNEQ           130226  030244
BLRTRC1 SYNCHRONOUS DIGITAL PATH FAULT SUPERVISION  SDIP     STATE     LAYER    K  L  M  FAULT  INFO    DATE    TIME
                                                    7ETM2    TRAFLIM   VC12-2   3  1  1  UNEQ           130226  030244
BLRTRC1 DIGITAL PATH QUALITY SUPERVISION            SDIP     STATE     LAYER    K  L  M  FAULT  INFO    DATE    TIME
                                                    7ETM2    TRAFLIM   VC12-8   3  3  1  UNEQ           130226  030244
BSC23   DIGITAL PATH QUALITY SUPERVISION            DIP      DIPPART  SESL2  QSV    SECTION  DATE    TIME
                                                    42MNPBS           1      1               130521  113000
BSC41   DIGITAL PATH FAULT SUPERVISION                  DIP      DIPEND   FAULT     SECTION   HG  DATE    TIME
                                                    BL2397            RDI                     130521  120407

here is the code i have worked on till now 这是我到目前为止一直在处理的代码

Sub Search11()
Dim TEST
Dim Today
Today = Now

Dim c(4) As Variant
Dim a(4) As Variant
a(0) = 1
For i = 0 To 3
Set Test20 = Range(Cells(a(i), 1), Cells(a(i) + 32, 1)).Find(What:="BLRTRC1")

If Test20 Is Nothing Then
GoTo LABEL1
Else
a(i + 1) = Test20.Row
c(i) = "BLRTRC1"
End If
LABEL1:    Next i

Dim d(4) As Variant
Dim b(4) As Variant
b(0) = 1
For i = 0 To 3
Set Test21 = Range(Cells(b(i), 1), Cells(b(i) + 32, 1)).Find(What:="BSC23")

If Test21 Is Nothing Then
GoTo LABEL2
Else
b(i + 1) = Test21.Row
d(i) = "BSC23"
End If
LABEL2:    Next i

Dim e(4) As Variant
Dim f(4) As Variant
e(0) = 1
For i = 0 To 3
Set Test21 = Range(Cells(e(i), 1), Cells(e(i) + 32, 1)).Find(What:="BSC41")

If Test21 Is Nothing Then
GoTo LABEL3
Else
e(i + 1) = Test21.Row
f(i) = "BSC41"
End If
LABEL3:    Next i


Dim o(3) As Variant
o(0) = "SYNCHRONOUS DIGITAL PATH FAULT SUPERVISION"
o(1) = "DIGITAL PATH QUALITY SUPERVISION"
o(2) = "DIGITAL PATH FAULT SUPERVISION"

Dim t(2) As Variant
t(0) = "SYNCHRONOUS DIGITAL PATH FAULT SUPERVISION/A1"
t(1) = "DIGITAL PATH QUALITY SUPERVISION/A3"
t(2) = "DIGITAL PATH FAULT SUPERVISION/A2"

Dim s(3) As Variant

s(0) = "SDIP"
s(1) = "DIP"
s(2) = "DIP"

R = 2
i = 0


For i = 0 To 3
k = 0
If a(i) > 0 Then

For k = 0 To 2
Set Test4 = Range(Cells(a(i), 1), Cells(a(i) + 10, 1)).Find(What:=o(k))

If Test4 Is Nothing Then
    GoTo NXTALARM
Else
    Set Test5 = Range(Cells(a(i), 1), Cells(a(i) + 10, 1)).Find(What:=s(k))
    If Test5 Is Nothing Then
    GoTo NXTALARM
    Else
    p = Test5.Row
    Cells(p + 1, 1).Select
    Selection.Copy
    Sheets("Sheet2").Activate
    Range("C" & R + 1).Select
    ActiveSheet.Paste
    Cells(R, 1).Value = c(i)
    Cells(R, 2).Value = t(k)
    Cells(R, 3).Value = Test5
    Cells(R, 4).Value = Today
    Sheets("Sheet4").Activate
    R = R + 2
End If
End If
NXTALARM: Next k

Else
End If

If b(i) > 0 Then

For k = 0 To 2
Set Test4 = Range(Cells(b(i), 1), Cells(b(i) + 10, 1)).Find(What:=o(k))

If Test4 Is Nothing Then
    GoTo NXTALARM2
Else
    Set Test5 = Range(Cells(b(i), 1), Cells(b(i) + 10, 1)).Find(What:=s(k))
    If Test5 Is Nothing Then
    GoTo NXTALARM2
    Else
    p = Test5.Row
    Cells(p + 1, 1).Select
    Selection.Copy
    Sheets("Sheet2").Activate
    Range("C" & R + 1).Select
    ActiveSheet.Paste
    Cells(R, 1).Value = d(i)
    Cells(R, 2).Value = t(k)
    Cells(R, 3).Value = Test5
    Cells(R, 4).Value = Today
    Sheets("Sheet4").Activate
    R = R + 2
End If
End If
NXTALARM2: Next k

Else
End If 
If e(i) > 0 Then

For k = 0 To 2
Set Test4 = Range(Cells(e(i), 1), Cells(e(i) + 10, 1)).Find(What:=o(k))

If Test4 Is Nothing Then
    GoTo NXTALARM2
Else
    Set Test5 = Range(Cells(e(i), 1), Cells(e(i) + 10, 1)).Find(What:=s(k))
    If Test5 Is Nothing Then
    GoTo NXTALARM3
    Else
    p = Test5.Row
    Cells(p + 1, 1).Select
    Selection.Copy
    Sheets("Sheet2").Activate
    Range("C" & R + 1).Select
    ActiveSheet.Paste
    Cells(R, 1).Value = f(i)
    Cells(R, 2).Value = t(k)
    Cells(R, 3).Value = Test5
    Cells(R, 4).Value = Today
    Sheets("Sheet4").Activate
    R = R + 2
End If
End If
NXTALARM3: Next k

Else
End If


'NXTALARM: Next k
NXTNODE: Next i

'Application.Run ("multiplebuttons")
'Application.Run ("CommentAddOrEdit")
   ' MsgBox a(55)
End Sub

This code of mine is causing 100s of duplicates to occur, and if i try to extend the ranges it stucks!! 我的这段代码导致100多次重复发生,如果我尝试扩展范围,就会卡住!!

http://postimg.org/gallery/oqk3ga8/ http://postimg.org/gallery/oqk3ga8/

You will make life a lot simpler if you change your output to be single line table entries rather than double line "paragraphs". 如果将输出更改为单行表条目而不是双行“段落”,则将使工作变得更加简单。 [You can reformat at a later stage if necessary.] As a 1st step, I would develop a "parser" to reformat your input - onto an adjacent worksheet - into single line entries. [如果需要,您可以在以后的阶段中重新格式化。]作为第一步,我将开发一个“解析器”以将您的输入(在相邻的工作表上)重新格式化为单行条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM