OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to make this a loop?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Spinalkord
Newbie
Newbie


Joined: 28 Jun 2008
Posts: 3

PostPosted: Sat Jun 28, 2008 11:01 pm    Post subject: How to make this a loop? Reply with quote

Hey guys I have this code and I am not sure as how to make it loop so I dont have to repeat the code all the way through. And I also want to make the code alot faster.


Code:
REM  *****  BASIC  *****
REM This is Version 1
REM Still working out how to do loops.
REM So for now this will take a bit of time to update the PacMix.

Sub DoUpdate
Dim Doc As Object
Dim oCell As Object
Dim Cell As Object
Dim SheetPMH As Object
Dim SheetPMH2 As Object
Doc = ThisComponent
SheetPMH = Doc.Sheets.getByName("PacMixHistory")
SheetPMH2 = Doc.Sheets.getByName("PacMixHistory")

 oRangeOrg = SheetPMH.getCellRangeByName("D3:E54").RangeAddress
 oRangeCpy = SheetPMH2.getCellRangeByName("E3").RangeAddress
 
 oCellCpy = SheetPMH2.getCellByPosition(oRangeCpy.StartColumn,oRangeCpy.StartRow).CellAddress
 SheetPMH.CopyRange(oCellCpy, oRangeOrg)

REM : Set Document and Sheet Ref

 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C3").Value
 Cell = SheetPMH.getCellRangeByName("D3")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C4").Value
 Cell = SheetPMH.getCellRangeByName("D4")
 Cell.Value = oStore
  oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C5").Value
 Cell = SheetPMH.getCellRangeByName("D5")
 Cell.Value = oStore
  oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C6").Value
 Cell = SheetPMH.getCellRangeByName("D6")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C7").Value
 Cell = SheetPMH.getCellRangeByName("D7")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C8").Value
 Cell = SheetPMH.getCellRangeByName("D8")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C9").Value
 Cell = SheetPMH.getCellRangeByName("D9")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C10").Value
 Cell = SheetPMH.getCellRangeByName("D10")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C11").Value
 Cell = SheetPMH.getCellRangeByName("D11")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C12").Value
 Cell = SheetPMH.getCellRangeByName("D12")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C13").Value
 Cell = SheetPMH.getCellRangeByName("D13")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C14").Value
 Cell = SheetPMH.getCellRangeByName("D14")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C15").Value
 Cell = SheetPMH.getCellRangeByName("D15")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C16").Value
 Cell = SheetPMH.getCellRangeByName("D16")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C17").Value
 Cell = SheetPMH.getCellRangeByName("D17")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C18").Value
 Cell = SheetPMH.getCellRangeByName("D18")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C19").Value
 Cell = SheetPMH.getCellRangeByName("D19")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C20").Value
 Cell = SheetPMH.getCellRangeByName("D20")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C21").Value
 Cell = SheetPMH.getCellRangeByName("D21")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C22").Value
 Cell = SheetPMH.getCellRangeByName("D22")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C23").Value
 Cell = SheetPMH.getCellRangeByName("D23")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C24").Value
 Cell = SheetPMH.getCellRangeByName("D24")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C25").Value
 Cell = SheetPMH.getCellRangeByName("D25")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C26").Value
 Cell = SheetPMH.getCellRangeByName("D26")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C27").Value
 Cell = SheetPMH.getCellRangeByName("D27")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C28").Value
 Cell = SheetPMH.getCellRangeByName("D28")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C29").Value
 Cell = SheetPMH.getCellRangeByName("D29")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C30").Value
 Cell = SheetPMH.getCellRangeByName("D30")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C31").Value
 Cell = SheetPMH.getCellRangeByName("D31")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C32").Value
 Cell = SheetPMH.getCellRangeByName("D32")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C33").Value
 Cell = SheetPMH.getCellRangeByName("D33")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C34").Value
 Cell = SheetPMH.getCellRangeByName("D34")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C35").Value
 Cell = SheetPMH.getCellRangeByName("D35")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C36").Value
 Cell = SheetPMH.getCellRangeByName("D36")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C37").Value
 Cell = SheetPMH.getCellRangeByName("D37")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C38").Value
 Cell = SheetPMH.getCellRangeByName("D38")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C39").Value
 Cell = SheetPMH.getCellRangeByName("D39")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C40").Value
 Cell = SheetPMH.getCellRangeByName("D40")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C41").Value
 Cell = SheetPMH.getCellRangeByName("D41")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C42").Value
 Cell = SheetPMH.getCellRangeByName("D42")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C43").Value
 Cell = SheetPMH.getCellRangeByName("D43")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C44").Value
 Cell = SheetPMH.getCellRangeByName("D44")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C45").Value
 Cell = SheetPMH.getCellRangeByName("D45")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C46").Value
 Cell = SheetPMH.getCellRangeByName("D46")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C47").Value
 Cell = SheetPMH.getCellRangeByName("D47")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C48").Value
 Cell = SheetPMH.getCellRangeByName("D48")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C49").Value
 Cell = SheetPMH.getCellRangeByName("D49")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C50").Value
 Cell = SheetPMH.getCellRangeByName("D50")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C51").Value
 Cell = SheetPMH.getCellRangeByName("D51")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C52").Value
 Cell = SheetPMH.getCellRangeByName("D52")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C53").Value
 Cell = SheetPMH.getCellRangeByName("D53")
 Cell.Value = oStore
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C54").Value
 Cell = SheetPMH.getCellRangeByName("D54")
End Sub


Thanks in Advance
Back to top
View user's profile Send private message
Mark B
Super User
Super User


Joined: 16 Feb 2007
Posts: 852
Location: Lincolnshire, UK

PostPosted: Sun Jun 29, 2008 1:03 am    Post subject: Reply with quote

Code:

Dim i as Integer
For i = 3 to 54
 oStore = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName("C" & i).Value
 Cell = SheetPMH.getCellRangeByName("D" & i)
 Cell.Value = oStore
Next i

Mark
_________________
Mark B's Articles
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Spinalkord
Newbie
Newbie


Joined: 28 Jun 2008
Posts: 3

PostPosted: Sun Jun 29, 2008 2:50 am    Post subject: WOW Reply with quote

Great thanks for that.

Now I understand how to do them.

This is great.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group