Posts: 17
Threads: 6
Joined: Oct 2013
Hello ,
I have a simple question and I wasn't able to get any results from using the search option.
I have a simple macro in VBA:
Sub Macrocslu2()
Range(Selection, Selection.End(xlToLeft)).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.Delete Shift:=xlUp
Range("D2").Select
End Sub
It basically gets the current selection and modifies it so I can delete the cells that I desire.
My question is , how can I integrate this macro in QM2?
I can't figure out how do I implement the "
Selection" bit in QM2.
Sergiu
Posts: 12,147
Threads: 143
Joined: Dec 2002
1. Get variable of type Excel.Application.
2. Use the variable wherever a function called without a variable.
Macro
Macro2142
ExcelSheet es.Init
Excel.Application app=es.ws.Application
app.Range(app.Selection, app.Selection.End(Excel.xlToLeft)).Select
app.Range(app.Selection, app.Selection.End(Excel.xlUp)).Select
app.Selection.Delete(Excel.xlUp)
app.Range("D2").Select
Posts: 17
Threads: 6
Joined: Oct 2013
Thank you Gintaras for the quick reply.

You're a good man.
Sergiu
Posts: 12,147
Threads: 143
Joined: Dec 2002
or
Macro
Macro2136
ExcelSheet es.Init
es.RunMacro("Macrocslu2")
Posts: 17
Threads: 6
Joined: Oct 2013
Thought of that but I have a lot of macro's in excel and I want to tidy up a bit and use more in QM2.
Thank you though!
Posts: 17
Threads: 6
Joined: Oct 2013
Hello ,
I have another macro that I can't figure out how to integrate it into QM2.
Sub AutoFill()
Dim LastRow As Long
LastRow = Columns(1).Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
ActiveCell.AutoFill Destination:=Range(ActiveCell, Cells(LastRow, ActiveCell.Column))
End Sub
When I tried to add property to Columns(1) function it tells me "Expected 0 arguments, not 1.";
Posts: 12,147
Threads: 143
Joined: Dec 2002
Posts: 17
Threads: 6
Joined: Oct 2013
Macro
Macro2
ExcelSheet es1.Init
Excel.Application app = es1.ws.Application
Excel.Range rng = es1.ws.Columns.Item(1)
rng.Find("*" Excel.xlByRows Excel.xlPrevious).Row
Error in Macro2: expected 6 to 9 arguments, not 3.
Do I really need to add 3 more arguments or is this a bug ?
Posts: 12,147
Threads: 143
Joined: Dec 2002
rng.Find("*" Excel.xlByRows Excel.xlPrevious @ @ 1).Row
With COM functions QM supports only VARIANT optional arguments. Look in status bar, take other values from there. VARIANT optional arguments can be @. The ` is for VARIANT.
Posts: 17
Threads: 6
Joined: Oct 2013
Set sourceRange = Worksheets("Sheet1").Range("A1:A2")
Set fillRange = Worksheets("Sheet1").Range("A1:A20")
sourceRange.AutoFill Destination:=fillRange
How can I declare fillRange with a variable inside it ?
For example I can get the number of Rows in a specified column store it in (int x) and I declare it in fillRange so that it stops filling when it gets to that column.
Macro
me27 testare extindere
int x;
ExcelSheet es.Init
Excel.Application app = es.ws.Application
;/I have another bit in this macro that gets the selection of first row
;x = app.Selection.Rows.Count
Excel.Range sourceRange=es.ws.Range("A1:A1")
;/I want to replace A20 with Ax or something like that
Excel.Range fillRange = es.ws.Range("A20:A20")
sourceRange.AutoFill(fillRange 0)
I hope you understand what I'm trying to do
Posts: 12,147
Threads: 143
Joined: Dec 2002