I want to specify a cell range in excel to paste a query too. I currently have code that I am using to add text to the spreadsheet such as formulas and labels.
Can anyone please help.
Thanks in advance
-----------------------------------
Dim mySheet As Object
Dim myBook As Object
Dim xlapp As Object
Set xlapp = Excel.Application
With xlapp
Workbooks.Open ("C:\3651H\monthlysales2.xls")
Set mySheet=Workbooks.Open("C:\3651H\Monthlysales2.xls").Sheets("Sheet1")
Sheets("sheet1").Name ([Forms]![monthly_report])
.Range("A1").Select
.ActiveCell.Value.Bold = "Date"
.Range("B1").Select
.ActiveCell.Value.Bold = "Store"
.Range("C1").Select
.ActiveCell.Value.Bold = "Product Code"
.Range("D1").Select
.ActiveCell.Value.Bold = "Sales (inc GST)"
.Range("C2").Select
.ActiveCell.FormulaR1C1 = "ABC-035 Total"
.Range("C3").Select
.ActiveCell.FormulaR1C1 = "AHJ-025 Total"
.Range("C4").Select
.ActiveCell.FormulaR1C1 = "AYB-1564 Total"
.Range("D2").Select
.ActiveCell.FormulaR1C1 = "=sum(Vlookup(""ABC-035"", C1
549,2,FALSE))"
.Range("D3").Select
.ActiveCell.FormulaR1C1 = "=SUM(VLOOKUP(""AHJ-025"",C1
549,2,FALSE))"
.Range("D4").Select
.ActiveCell.FormulaR1C1 = "=SUM(VLOOKUP(""AYB-1564"",C1
549,2,FALSE))"
End With
xlapp.Quit
Set xlapp = Nothing
-------------------------------------
Some people make things happen, some watch while things happen, and some wonder 'What happened?'
Can anyone please help.
Thanks in advance
-----------------------------------
Dim mySheet As Object
Dim myBook As Object
Dim xlapp As Object
Set xlapp = Excel.Application
With xlapp
Workbooks.Open ("C:\3651H\monthlysales2.xls")
Set mySheet=Workbooks.Open("C:\3651H\Monthlysales2.xls").Sheets("Sheet1")
Sheets("sheet1").Name ([Forms]![monthly_report])
.Range("A1").Select
.ActiveCell.Value.Bold = "Date"
.Range("B1").Select
.ActiveCell.Value.Bold = "Store"
.Range("C1").Select
.ActiveCell.Value.Bold = "Product Code"
.Range("D1").Select
.ActiveCell.Value.Bold = "Sales (inc GST)"
.Range("C2").Select
.ActiveCell.FormulaR1C1 = "ABC-035 Total"
.Range("C3").Select
.ActiveCell.FormulaR1C1 = "AHJ-025 Total"
.Range("C4").Select
.ActiveCell.FormulaR1C1 = "AYB-1564 Total"
.Range("D2").Select
.ActiveCell.FormulaR1C1 = "=sum(Vlookup(""ABC-035"", C1
.Range("D3").Select
.ActiveCell.FormulaR1C1 = "=SUM(VLOOKUP(""AHJ-025"",C1
.Range("D4").Select
.ActiveCell.FormulaR1C1 = "=SUM(VLOOKUP(""AYB-1564"",C1
End With
xlapp.Quit
Set xlapp = Nothing
-------------------------------------
Some people make things happen, some watch while things happen, and some wonder 'What happened?'