gjiaxin1989
New Member
- Joined
- Jul 16, 2013
- Messages
- 5
Hi,
I am trying to write a macro sub that searches for a certain string in column X and copy the values in column I and K on the same row onto another workbook. Values from I will be copied to cell B15 in the new workbook, and values from K will be pasted to cell D15. The next matching values will be pasted at B16, D16, and so on.... I have read jlevesquire's thread http://www.mrexcel.com/forum/excel-...y-certain-cells-same-row-different-sheet.html. I think what I'm looking for is very similar to what he wanted. However, after editing his code to meet mine, it is not working. Especially the Offset(1) part. It says that its missing a "=". Can someone please help me? Here is my code:
And can someone show me how to upload my spreadsheet? I am new to this forum... Thanks a million
Natalie
I am trying to write a macro sub that searches for a certain string in column X and copy the values in column I and K on the same row onto another workbook. Values from I will be copied to cell B15 in the new workbook, and values from K will be pasted to cell D15. The next matching values will be pasted at B16, D16, and so on.... I have read jlevesquire's thread http://www.mrexcel.com/forum/excel-...y-certain-cells-same-row-different-sheet.html. I think what I'm looking for is very similar to what he wanted. However, after editing his code to meet mine, it is not working. Especially the Offset(1) part. It says that its missing a "=". Can someone please help me? Here is my code:
Code:
Sub CommandButton1_Click()
Dim wsSource As Worksheet
Dim wbSource As Workbook
Dim wsTarget As Worksheet
Dim wbTarget As Workbook
Dim findRange As Range
Dim newForm As Workbook
Dim J As Integer
Application.ScreenUpdating = False
Set wbSource = ThisWorkbook
Set wsSource = wbSource.Sheets(1)
Set wbTarget = Workbooks.Open("C:\FilePath")
Set wsTarget = wbTarget.Sheets(1)
wsTarget.Activate
Set findRange = wsTarget.Range("A1:H11")
findRange.Replace What:="xxx-Project.No", Replacement:=wsSource.Range("s5:w5").Value, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
ActiveWorkbook.SaveCopyAs Filename:="C:\FilePath_NEW"
ActiveWorkbook.Close False
Set newForm = Workbooks.Open("C:\FilePath_New")
J = 1
Dim setrng As Range
Set setrng = wsSource.Columns("X:X")
setrng.AutoFilter Field:=1, Criteria1:="Y"
wsSource.Range(wsSource.Range("I9").Offset(1), wsSource.Range("I9").End(xlDown)).Copy_
newForm.Range("B" & Rows.Count).End(xlUp).Offset (1)
wsSource.Range(wsSource.Range("K9").Offset(1), wsSource.Range("K9").End(xlDown)).Copy_
newForm.Range("D" & Rows.Count).End(xlUp).Offset (1)
End Sub
And can someone show me how to upload my spreadsheet? I am new to this forum... Thanks a million
Natalie