2014-01-23 83 views
0

我有許多國家的文件,我必須獲取單詞(哪一個在列A中),然後複製該單詞的%(列中的15%我)並將其粘貼在其他一些表格中。查找單詞並複製另一個表格中的值

我想從第一張表找到windows 8和windows平板電腦並粘貼到第二張表中。

我從Shiddarth潰敗的博客中找到一個宏來幫助找到這個詞。我已經複製下面。但是我需要在找到這個詞後複製並粘貼另一個excel表格中的百分比。你能幫我解決這個問題嗎?

對於防爆:enter image description here enter image description here

Sub Sample1() 
Dim oSht As Worksheet 
Dim lastRow As Long, i As Long 
Dim strSearch As String 
Dim aCell As Range 
t = GetTickCount 
On Error GoTo Err 
Set oSht = Sheets("Sheet1") 
lastRow = oSht.Range("A" & Rows.Count).End(xlUp).Row 
strSearch = "Windows 8" 
Set aCell = oSht.Range("A1:A" & lastRow).Find(What:=strSearch, LookIn:=xlValues, _ 
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
MatchCase:=False, SearchFormat:=False) 
If Not aCell Is Nothing Then 
    MsgBox "Value Found in Cell " & aCell.Address & vbCrLf & _ 
"and it took " & GetTickCount - t & "milliseconds" 
End If 
Exit Sub 
Err: 
    MsgBox Err.Description 
End Sub 

回答

0

我略微你提出你的問題的方式感到困惑,但我相信我可以幫助你。

aCell將具有.Row和.Column的屬性以專門引用數據,但在從同一行或列中提取單元格值時也很有用。

使用Range.Copy方法對您來說可能是最簡單的。

aCell.Copy destination:=Worksheets("Sheet2").Range("A1") 

aCell.Copy 
Sheets("Sheet2").Range("A1").PasteSpecial (xlPasteValues) 

然後你可以決定你想粘貼值。當我重讀您的問題時,您似乎希望找到該值,然後將該值複製到另一列。然後你會使用。

Sheets("Sheet1").Range("I" & aCell.Row).Copy destination:=Worksheets("Sheet2").Range("A1") 

或沿着這些線。

+0

這正是我一直在尋找的東西。非常感謝您的幫助。 – Tanuvi

相關問題