[Solved] Copy A1 to first empty cell in column B

Discuss the spreadsheet application
Post Reply
raciret
Posts: 11
Joined: Thu Mar 03, 2016 7:17 am

[Solved] Copy A1 to first empty cell in column B

Post by raciret »

Hello,

I'm new in using OpenOffice Calc. I'm creating a spreadsheet and I want to copy the value of "A1" and paste it to the last blank/empty cell in column B.

I found some codes that finds the last non-empty cell but cannot find one that would find the last empty cell, and that can work if only I could insert a "Row + 1" like in Excel.

Any help would be appreciated. Thank you!
Last edited by MrProgrammer on Wed Oct 28, 2020 6:35 pm, edited 1 time in total.
Reason: Tagged ✓ [Solved]
OpenOffice 4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Find Last Empty Cell in a Row

Post by Zizi64 »

I found some codes that finds the last non-empty cell but cannot find one that would find the last empty cell,
The last empty cell in a row located in the 1,073,741,824-th row. (I can not imagine if you need insert some data into the 1,073,741,824-row: therefore it is will be empty, and it is the last cell ...

...Or do you need find the FIRST empty cell? Or do you need find the last empty cell in a non empty cell range?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
raciret
Posts: 11
Joined: Thu Mar 03, 2016 7:17 am

Re: Find Last Empty Cell in a Row

Post by raciret »

Yes, I need the last empty cell in a non empty cell range.
OpenOffice 4 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Find Last Empty Cell in a Row

Post by Zizi64 »

As far as I know, you can not fint it by Find & Replace function. An empty cell never matches anything.
But you can use a helper column, and some formulas on the non empty cellrange in the column C:

Code: Select all

IF(ISBLANK(B1);ROW();"")
And then you need copy/paste the formula into the non empty cellrange.

Then you can find the maximum of the displayed row numbers by the MAX() function.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11361
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Find Last Empty Cell in a Row

Post by Zizi64 »

Or you can write (not to record it) a short macro code to achieve this task. The macro will paste the content of the clipboard (or the content of the cell A1) into the last empty cell of a selected (or a given) cellrange in a specific column. A cyclic macro can find the empty cells in a specific cellrange.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Find Last Empty Cell in a Row

Post by Lupp »

What about

Code: Select all

=HYPERLINK("#"&ADDRESS(SUMPRODUCT(MAX(ROW(B2:B31)*ISBLANK(B2:B31)));COLUMN(B2)))
in C1 e.g.?
This formula will not only find the address of the last blank cell within the range B2:B31 (part of a column!), but also create a link to jump to that cell (select it).

For application in BASIC code you have to pass the parameters, of course (always a problem for 'Sub'), and to use a function access object for the Calc functions. The HYPERLINK function will be omitted then.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
MrProgrammer
Moderator
Posts: 4908
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Find Last Empty Cell in a Row

Post by MrProgrammer »

raciret wrote:I want to copy the value of "A1" and paste it to the last blank/empty cell in column B.
The simple way is to copy the value, use Lupp's HYPERLINK function, then paste. If you want a macro, read Help → Index → shortcut keys;spreadsheets. You don't need to write a macro. You can record one with Tools → Macros → Record. Here is what I got:
sub T83777
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Sel"
args1(0).Value = false

dispatcher.executeDispatch(document, ".uno:GoToStart", "", 0, args1())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem ----------------------------------------------------------------------
dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "By"
args3(0).Value = 1
args3(1).Name = "Sel"
args3(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args3())

rem ----------------------------------------------------------------------
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "By"
args4(0).Value = 1
args4(1).Name = "Sel"
args4(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDownToEndOfData", "", 0, args4())

rem ----------------------------------------------------------------------
dim args5(1) as new com.sun.star.beans.PropertyValue
args5(0).Name = "By"
args5(0).Value = 1
args5(1).Name = "Sel"
args5(1).Value = false

dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args5())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())

rem ----------------------------------------------------------------------
dim args7(0) as new com.sun.star.beans.PropertyValue
args7(0).Name = "Sel"
args7(0).Value = false

dispatcher.executeDispatch(document, ".uno:GoToStart", "", 0, args7())


end sub
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Post Reply