Excelnoobisme
Board Regular
- Joined
- Nov 19, 2010
- Messages
- 128
Hi i have a worksheet name "Working on amount Mar 2011" i need to paste some data depending on the date to another worksheet. The below is my vba code which work.
Sub Testing()
ActiveSheet.Name = "Today"
Workbooks.Open Filename:= _
"C:\Program File\Shared Files\Export Amount Mar 2011.xlsx"
Dim ff As Range
Set Found = Workbooks("Export Amount Mar 2011.xlsx").Sheets("Loc1").Columns("A").Find(what:=Workbooks("Working on Amount Mar 2011.xlsm").Sheets("Today").Range("A3").Value, LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
MsgBox "Not found"
Else
Workbooks("Working on Amount Mar 2011.xlsm").Sheets("Today").Range("T12:T15").Copy
Workbooks("Export Amount Mar 2011.xlsx").Sheets("Loc1").Range(Found.Address).Offset(0, 1).PasteSpecial Paste:=xlPasteValues
End If
ActiveWorkbook.Save
ActiveWindow.Close
ActiveSheet.Name = Range("TodayDate").Value
End Sub
Now i need to change the worksheet name to be more flexible so as i dont need to change the code everymonth.The below code always give me a runtime error. Any1 can advise what is wrong?
Sub Testing()
ActiveSheet.Name = "Today"
ActiveWorkbook.Windows(1).Caption = "1"
Set objExcel = CreateObject("Excel.Application")
Workbooks.Open Filename:= _
"C:\Program File\Shared Files\Export Amount Mar 2011.xlsx"
objExcel.Visible = True
Set objExcel = Nothing
ActiveWorkbook.Activate
ActiveWorkbook.Windows(1).Caption = "2"
Dim ff As Range
Set Found = Workbooks("2.xlsx").Sheets("Loc1").Columns("A").Find(what:=Workbooks("1.xlsm").Sheets("Today").Range("A3").Value, LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
MsgBox "Not found"
Else
Workbooks("1.xlsm").Sheets("Today").Range("T12:T15").Copy
Workbooks("2.xlsx").Sheets("Loc1").Range(Found.Address).Offset(0, 1).PasteSpecial Paste:=xlPasteValues
End If
ActiveWorkbook.Save
ActiveWindow.Close
ActiveSheet.Name = Range("TodayDate").Value
End Sub
Sub Testing()
ActiveSheet.Name = "Today"
Workbooks.Open Filename:= _
"C:\Program File\Shared Files\Export Amount Mar 2011.xlsx"
Dim ff As Range
Set Found = Workbooks("Export Amount Mar 2011.xlsx").Sheets("Loc1").Columns("A").Find(what:=Workbooks("Working on Amount Mar 2011.xlsm").Sheets("Today").Range("A3").Value, LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
MsgBox "Not found"
Else
Workbooks("Working on Amount Mar 2011.xlsm").Sheets("Today").Range("T12:T15").Copy
Workbooks("Export Amount Mar 2011.xlsx").Sheets("Loc1").Range(Found.Address).Offset(0, 1).PasteSpecial Paste:=xlPasteValues
End If
ActiveWorkbook.Save
ActiveWindow.Close
ActiveSheet.Name = Range("TodayDate").Value
End Sub
Now i need to change the worksheet name to be more flexible so as i dont need to change the code everymonth.The below code always give me a runtime error. Any1 can advise what is wrong?
Sub Testing()
ActiveSheet.Name = "Today"
ActiveWorkbook.Windows(1).Caption = "1"
Set objExcel = CreateObject("Excel.Application")
Workbooks.Open Filename:= _
"C:\Program File\Shared Files\Export Amount Mar 2011.xlsx"
objExcel.Visible = True
Set objExcel = Nothing
ActiveWorkbook.Activate
ActiveWorkbook.Windows(1).Caption = "2"
Dim ff As Range
Set Found = Workbooks("2.xlsx").Sheets("Loc1").Columns("A").Find(what:=Workbooks("1.xlsm").Sheets("Today").Range("A3").Value, LookIn:=xlValues, lookat:=xlWhole)
If Found Is Nothing Then
MsgBox "Not found"
Else
Workbooks("1.xlsm").Sheets("Today").Range("T12:T15").Copy
Workbooks("2.xlsx").Sheets("Loc1").Range(Found.Address).Offset(0, 1).PasteSpecial Paste:=xlPasteValues
End If
ActiveWorkbook.Save
ActiveWindow.Close
ActiveSheet.Name = Range("TodayDate").Value
End Sub