| View previous topic :: View next topic |
| Author |
Message |
voodooo Newbie

Joined: 24 Feb 2012 Posts: 2
|
Posted: Fri Feb 24, 2012 3:37 am Post subject: helps in conversion of a macro to OpenOffice |
|
|
Hello, I ask for your help
Use a macro in M$excel that does what is shown below
Two columns to a column
A B
6 7
3 5
9 1
--------
shows
A
B
6
7
3
5
9
1
i use VB code in MACRO
| Code: |
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
' transpor linhas para colunas
'
' Keyboard Shortcut: Ctrl+t
'
Public Sub loopMe()
Dim c As Excel.Range
Dim r As Excel.Range
Dim e As Excel.Range
Dim w As Excel.Worksheet
Dim s As Excel.Worksheet
Dim i As Integer
Set s = Application.ActiveSheet
Set w = Application.ActiveWorkbook.Worksheets.Add
i = 1
For Each c In Intersect(s.UsedRange, s.Columns(1)).Cells
Set r = Intersect(c.EntireRow, c.Parent.UsedRange)
For Each e In r.Cells
w.Cells(i, 1).Value = e.Value
i = i + 1
Next e
Next c
End Sub
|
I tried to convert this code, but did not work
Who can give me a hand?
Tagged code - floris v, moderator |
|
| Back to top |
|
 |
range General User

Joined: 04 Jan 2012 Posts: 21
|
Posted: Fri Feb 24, 2012 6:47 am Post subject: |
|
|
You should be able to achieve the same thing using formulae. Assuming your data is in columns A1 and B1 downwards,
| Code: | | C1=INDEX($A$1:$A$65536;(ROW()+1)/2) |
| Code: | | C2=INDEX($B$1:$B$65536;ROW()/2) |
Then highlight C1 AND C2 together at the same time and copy down column C to two times the row number of your data. |
|
| Back to top |
|
 |
voodooo Newbie

Joined: 24 Feb 2012 Posts: 2
|
Posted: Sat Feb 25, 2012 3:32 am Post subject: |
|
|
for this to work I always have to put that content in the two cells (C1 and C2, or other 2 cell)
is possible to make a macro, to operate in automatic mode  |
|
| Back to top |
|
 |
Villeroy Super User


Joined: 04 Oct 2004 Posts: 10065 Location: Germany
|
Posted: Sat Feb 25, 2012 4:34 am Post subject: |
|
|
Of course it is possible, but why? If you want to program spreadsheets rather than using them you should simply program. If VBA is all you can program then you should make your decision. Carry on with macro code that works only with one particular program or start using spreadsheets in a more productive manner. Filling out values and formulas in any context is a piece of cake.
Instead of your VBA code you may consider scenarios.
http://user.services.openoffice.org/en/forum/download/file.php?id=3004 _________________ Rest in peace, oooforum.org
Get help on http://forum.openoffice.org |
|
| Back to top |
|
 |
martin_p General User

Joined: 22 Feb 2012 Posts: 10 Location: Indonesia
|
Posted: Sat Feb 25, 2012 5:41 pm Post subject: |
|
|
Several months ago, i had similar problem. So, wrote :
| Code: | REM ***** BASIC *****
Option Explicit
Sub Main
Dim oDoc As Object
Dim oSheet As Object
Dim xCellRange As Object
Dim data() As Object
Dim col As Integer
Dim i As Integer, j As Integer, k As Integer
k = 1
oDoc = ThisComponent
oSheet = oDoc.getSheets().getByIndex(0) ' Assuming your data are in the first sheet
xCellRange = oSheet.getCellRangeByName("A2:B11")
data = xCellRange.getDataArray()
For i = 0 To UBound(data)
For j = 0 To UBound(data(i))
oSheet.getCellbyPosition(2, k).SetValue(data(i)(j)) ' 2 means show result to col. B
k = k+1
Next j
Next i
End Sub |
Unless you will have to do this over and over and over again, or unless this is only part of larger and more complex operation, I agree with Villeroy. Write a code for a particular function only and you would waste your time on trivial matter, just like I did months ago.
But if you are really interested in OOo API, check this:
http://www.openoffice.org/api |
|
| Back to top |
|
 |
|