Hi,
Workbook 1
File and sheet names are always different. Only one sheet to start with. Macro to run from here and return here...
Workbook 2
File and sheet names are always the same.
I am trying to create a macro which in current workbook (1) creates a new sheet, opens another workbook (2), copies data, goes back to workbook 1 and pastes data on the new sheet. Goes back to first/original sheet in same workbook 1 (always different sheet name) and inserts a formula. Closes workbook 2.
I tried to write the following myself but get Compile Error: Expected Function or variable. With .activate highlighted. I expect that .Select will also produce an error. See blue text in code below.
Can someone advice how to correct my erros or do this differently? (VBA newbie/beginner)
Thanks
Workbook 1
File and sheet names are always different. Only one sheet to start with. Macro to run from here and return here...
Workbook 2
File and sheet names are always the same.
I am trying to create a macro which in current workbook (1) creates a new sheet, opens another workbook (2), copies data, goes back to workbook 1 and pastes data on the new sheet. Goes back to first/original sheet in same workbook 1 (always different sheet name) and inserts a formula. Closes workbook 2.
I tried to write the following myself but get Compile Error: Expected Function or variable. With .activate highlighted. I expect that .Select will also produce an error. See blue text in code below.
Can someone advice how to correct my erros or do this differently? (VBA newbie/beginner)
Code:
Sub MacroMultLoc()
'
' MacroMultLoc Macro
' Macro recorded 29-09-2010 by
'
'
Dim Bk1 As Workbook
Dim Sh1 As Worksheet
Set Bk1 = ThisWorkbook
Set Sh1 = ActiveSheet
Sheets.Add
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "ItemLocations"
Range("A1").Select
ChDir "K:\Sample\DoNotMove"
Workbooks.Open Filename:="K:\Sample\DoNotMove\ItemsLocationReport.xls"
Columns("A:F").Select
Selection.Copy
[B][COLOR=blue]With Bk1.[/COLOR][COLOR=blue]Activate[/COLOR][/B]
ActiveSheet.Paste
Range("A1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Warehouse"
Range("B1").Select
ActiveCell.FormulaR1C1 = "ItemNo"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Location"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Amount"
Range("G1").Select
[COLOR=blue][B]With Sh1.Select[/B][/COLOR]
Dim LR As Long
LR = Range("L" & Rows.Count).End(xlUp).Row
Range("p2:p" & LR).FormulaR1C1 = "=IF(SUMPRODUCT((ItemLocations!C[-14]=RC[-4])*(ItemLocations!C[-13]=RC[4]))>0,""No"",""Yes"")"
ItemsLocationReport.xls.Close savechanges:=False
Range("L1").Select
End Sub
Thanks