Basically I am trying to use the macros below that someone else gave to me with another set of cells but in a different way. But, it doesn’t work like it should and I am trying to figure out which line (or lines) is limiting how the macros work.
Let me explain how the macro below works for me and what I want it to do.
- The
mySourceCell
has a dropdown list in it with a series of selections. I select one and if I like it I click a button that runs the macro below and it takes the text in mySourceCell and puts it into the first empty cell in the myTargetRange series of cells. It then clears out mySourceCell so I can make another selection if I so choose. - I now want to use that macro in a different button that will take the myTargetRange series of cells and move them all to another list (call it myOwnRange) that can and will have other entries in it. Then it will clear out the myTargetRange cells.
3.The issue is it only moves the first cell in myTargetRange over to myOwnRange then clears out that first cell in myTargetRange, but it doesn’t do anything with the other cells at all.
Could it be theoSourceCell
line in the first macro below that is causing it to only move one line at a time?
REM ***** BASIC *****
Option Explicit
Sub PutDataIntoFirstEmptyRowOfTheTargetRange
Dim oDoc as object
Dim oSourceRange as object
Dim oSourceCell as object
Dim oTargetRange as object
Dim oTargetCell as object
Dim lColNr as long
Dim sFormula as string
oDoc = ThisComponent
oSourceRange = GetNamedRange("mySourceCell", oDoc)
oSourceCell = oSourceRange.ReferredCells.getCellByPosition(0,0)
sFormula = oSourceCell.Formula
oTargetRange = GetNamedRange("myTargetRange", oDoc)
lColNr = 0 'zero based numbering
oTargetCell = GetFirstEmptyCellInAColumnOfRange(oTargetRange, lColNr)
oTargetCell.Formula = sFormula
oSourceCell.Formula = ""
end Sub
'_____________________________________________________________________________________________
Function GetNamedRange(sRange_name as string, optional oCalc_File as object) as object
Dim oDoc, oRange as object
If IsMissing(oCalc_File) then
oDoc = ThisComponent
else
oDoc = oCalc_file
end if
If len(sRange_name) = 0 or sRange_name = "" then
GetNamedRange = NOTHING
Exit function
End if
if oDoc.namedranges.hasByName(sRange_name) then
oRange = oDoc.NamedRanges.getByName(sRange_name)
GetNamedRange = oRange
else
GetNamedRange = NOTHING
end if
end function
'_____________________________________________________________________________________________
Function GetFirstEmptyCellInAColumnOfRange(oTheRange as object, lColNr as long) as object
Dim oCells as object
Dim oCell as object
Dim lRowNr as long
Dim i as long
oCells = oTheRange.ReferredCells
lRowNr = oCells.Rows.Count
For i = 0 to lRowNr-1
oCell = oCells.getCellByPosition(lColNr,i)
If oCell.getType() = 0 Then
GetFirstEmptyCellInAColumnOfRange = oCell
Exit function
end if
next i
end function
'_____________________________________________________________________________________________
I am hoping someone can explain this to me so I can try and figure out how to get it to work correctly (with some help of course).