Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Integrate VBA to QM2
#1
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:

Code:
Copy      Help
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
#2
1. Get variable of type Excel.Application.
2. Use the variable wherever a function called without a variable.

Macro Macro2142
Code:
Copy      Help
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
#3
Thank you Gintaras for the quick reply. Smile
You're a good man.

Sergiu
#4
or
Macro Macro2136
Code:
Copy      Help
ExcelSheet es.Init
es.RunMacro("Macrocslu2")
#5
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!
#6
Hello ,
I have another macro that I can't figure out how to integrate it into QM2.

Code:
Copy      Help
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.";
#7
Columns.Item(1)
#8
Macro Macro2
Code:
Copy      Help
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 ?
#9
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.
#10
Code:
Copy      Help
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
Code:
Copy      Help
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 Smile
#11
F"A{x}:A{x}"


Forum Jump:


Users browsing this thread: 1 Guest(s)