2017-02-13 36 views
-1

I下載具有多個行和無限列的excel文件。在列中搜索帶有前綴的單詞,並將帶有前綴的整個單詞複製到同一張表上的另一列

在特定的行中,我們有數據,其中每個單元格都包含特定產品的詳細信息,按Alt + Enter分隔。

我必須通過複製粘貼來拉動2-3個這樣的描述的數據以從巨大的列表中分離產品。

如: -

_A_______B____________C____D___E___F___G______H_________________________________ 
    | Product  | Range |A | B | C |D |description|.... 
________________________________________________________________________________ 
1 | Apple  | R 1 |A1| B1| C1|D1| Description1 
              Description2 
              Description3 
              Description4 
________________________________________________________________________________ 
2 | ball  | R 1 |A1| B1| C1|D1| Description1 
              Description2 
              Description3 
              Description4 

從上面的例子我需求量的是內容詳細薩伊DLL的前綴複製:123456或LLM:654321和相同的複製到下一行。

這將有助於分離具有特殊描述的產品。

+0

讓我們更清楚。我有這個權利嗎?對於在列A中編入索引並在列B中命名的每一行項目,在一個單元格列H中有多個描述。如果第1行中的其中一個描述(例如「Apple Row」)應該具有描述前綴爲LLM:654321,那麼你想複製整個描述並粘貼到「下一行」,這將是第2行,名爲「球」? –

回答

0

如果你在尋找什麼:

APPLE ABCDEFGH 2460 APPLE:2460

        6521 APPLE : 6521 
            4532 APPLE : 4532 
            3021 APPLE : 3021 
            1234 APPLE : 1234 

BALL 6521 BALL:6521 4532 BALL:4532 3021 BALL:3021 1234 BALL:1234

然後創建一個列並使用此公式。您也可以使用自己的前綴

= IF(ISBLANK(A2),LEFT(A1,(SEARCH( 「:」,A1))& 「」 & L2),A2 & 「:」 & L2)

0

基於什麼我猜你需要:這可能讓你開始:

Sub Example1() 
Dim rowArray() As Variant, rowArrayCounter As Long 
Dim myStringArray, itemThatIwant As String, rowItIsIn As Long 

' The following code will find all instances of "LLM: 654321" in column "F" 
' It places the row number of each one into an array called rowArray() 
' and places the value of that item into a variable called itemThatIwant 

' The "split" function assumes that you enttered each list into a single cell 
' by using alt-enter to put them on individual lines within that cell. If so, then 
' the split delimiter would be chr(10), as below. Otherwise it will probably be one space 
' but you will need to find the correct delimiter for this to work. 

rowArrayCounter = 1 
ReDim rowArray(1 To 1) 
With Worksheets(1).Range("F1:F250") 
    Set c = .Find("LLM: 654321", LookIn:=xlValues)' this text is what you change 
    If Not c Is Nothing Then 
     firstAddress = c.Address 
     Do 
      myString = Split(c.Value, Chr(10)) ' split cell list into separate items 
      For i = LBound(myString) To UBound(myString) 
       If Left(myString(i), 11) = "LLM: 654321" Then 
        itemThatIwant = myString(i) 
        rowItIsIn = c.Row 
        ReDim Preserve rowArray(1 To rowArrayCounter) 
        rowArray(rowArrayCounter) = c.Row 
         ' do your events with data 
         ' the entire item (if found) is in the variable itemThatIwant 
        Exit For 
       End If 
      Next i 
      Set c = .FindNext(c) 
     Loop While Not c Is Nothing And c.Address <> firstAddress 
    End If 
End With 


End Sub 
+0

嗨約翰 - 我是宏觀世界的新手。我期待着一個工作宏我試圖運行這個,但沒有結果..我相信,這是因爲缺乏什麼和在哪裏做必要的必要改變的知識。我不確定你是否可以幫助我解決這個問題。非常感謝您的付出和努力。 – user7557520

+0

該示例搜索了您的示例文本「LLM:654321」的頁面。看看「這段文字就是你所改變的」。您可以將「LLM:654321」更改爲您正在搜索的任何內容。我猜「法律評估:654321」不在您搜索的頁面上。 –

相關問題