Changing a variable in a macro with a macro

So referencing my past question on selecting a range of cells.

Sub column_SelectVisible()
REM Selects the first <lNumberOfCells> visible cells in column <lColumnIndex> in the current Sheet.
    Const lColumnIndex   As Long = 0
    Const lNumberOfCells As Long = 200

    Dim oDoc    As Object : oDoc    = ThisComponent
    Dim oSheet  As Object : oSheet  = oDoc.CurrentController.ActiveSheet
    Dim oColumn As Object : oColumn = oSheet.Columns.getByIndex( lColumnIndex )
    Dim oRanges As Object : oRanges = oColumn.queryVisibleCells()
    Dim oRange  As Object : oRange  = oRanges.getByIndex(0)

    Dim oCursor As Object : oCursor = oSheet.createCursorByRange( oRange )
    oCursor.collapseToSize ( 1, lNumberOfCells )
    oDoc.CurrentController.select( oCursor )
End Sub

I now just need to be able to change the column select variable lColumnIndex to increment as a way to select a different column with 0 being column A, 1 = B and so on. I’m terrible with programming so I kind of do need to be hand held into this.

@ERas Please note. While the volunteers here are very willing to help with problems, do not utilize the site as a free programming service. If you are terrible with programming, who is going to maintain the code?

Understandable. It’s really just that I can’t grasp the language and it would genuinely take a year or so to understand. But I am reading the code given to me and trying to make sense of it.

Hello again @ERas,

i made a few adjustments to the code; the method column_SelectNext() is now the method to be connected to a Toolbar button / Keyboard Shortcut :

Global g_NextColumnIndex As Long

Sub column_SelectNext()
REM Select a block of visible cells in the next column.
REM To reset the column counter, set g_NextColumnIndex = 0 ( or restart LO ).
	column_SelectVisible( g_NextColumnIndex )
	g_NextColumnIndex = g_NextColumnIndex + 1        REM increment by 1.
End Sub

Sub column_SelectVisible( lColumnIndex As Long )
REM Selects the first <lNumberOfCells> visible cells in column <lColumnIndex> in the current Sheet.
	Const lNumberOfCells As Long = 200

	Dim oDoc    As Object : oDoc    = ThisComponent
	Dim oSheet  As Object : oSheet  = oDoc.CurrentController.ActiveSheet
	Dim oColumn As Object : oColumn = oSheet.Columns.getByIndex( lColumnIndex )
	Dim oRanges As Object : oRanges = oColumn.queryVisibleCells()
	Dim oRange  As Object : oRange  = oRanges.getByIndex(0)
	Dim oCursor As Object : oCursor = oSheet.createCursorByRange( oRange )
	
	oCursor.collapseToSize ( 1, lNumberOfCells )
	oDoc.CurrentController.select( oCursor )
End Sub

+1 for gritting teeth. :slight_smile:

Much obliged, i used to do that for real during my sleep for a couple of years… it could be stress-related.
I always appreciate to see “newcomers” learn to use macros in LibreOffice :slight_smile: