Advice to move/edit array from module to worksheet

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,602
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Spent ages looking for an issue of which ive now sorted so because of that i wish to move/edit the array from its module hiding place to the sheet itself.

Here is the code on the sheet.

Rich (BB code):
Sub Navigate(ByVal Direction As XlSearchDirection)
    Dim i As Integer
    Dim lastRow As Long
    
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    r = IIf(Direction = xlPrevious, r - 1, r + xlNext)
    
    'ensure value of r stays within data range
    If r < startRow Then r = startRow
    If r > lastRow Then r = lastRow
    
    'get record
    For i = 1 To UBound(ControlNames)
         Me.Controls(ControlNames(i)).Text = IIf(Direction = xlNone, "", ws.Cells(r, i).Text)
         
    Next i
    
    Me.Caption = "Database"
    
    'set enabled status of next previous buttons
    Me.NextRecord.Enabled = IIf(Direction = xlNone, False, r < lastRow)
    Me.PrevRecord.Enabled = IIf(Direction = xlNone, False, r > startRow)
    
    EventsEnable = False
    Me.ComboBoxCustomersNames.ListIndex = IIf(Direction = xlNone, -1, r - startRow)
    EventsEnable = True

End Sub

In the above code the line in Red calls a module.

Rich (BB code):
Function ControlNames() As Variant
ControlNames = Array("txtCustomer", "txtRegistrationNumber", "txtBlankUsed", "txtVehicle", _
                    "txtButtons", "txtKeySupplied", "txtTransponderChip", "txtJobAction", _
                    "txtProgrammerCloner", "txtKeyCode", "txtBiting", "txtChassisNumber", _
                    "txtJobDate", "txtVehicleYear", "txtPaid", "txtInvoiceNumber", "txtNotes", _
                    "txt1Address", "txt2Address", "txt3Address", "txt4Address", "txtPostCode", _
                    "txtTelNumber", "txtSecurityCode", "txtManual", "txtInfo", "txtSupplier", "txtPartNumber", "txtPaymentType", "txtPinCode")
End Function

Im looking to have the code on the sheet & not the module.
Please advise so i can take it from there.
 

Attachments

  • EaseUS_2024_07_ 8_16_02_32.jpg
    EaseUS_2024_07_ 8_16_02_32.jpg
    105.7 KB · Views: 20

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Like this:

Rich (BB code):
Function ControlNames() As Variant
    ControlNames = Application.Transpose(Sheets("sheetName").Range("a1:a5").Value2)
End Function
 
Upvote 0
Would that be on the worksheet with the code or in a module
 
Upvote 0
In the module, it's a direct replacement for your existing ControlNames function.

In the example, you'd have the control names in range a1 to A5
 
Upvote 0
Ok
My issue is I dont want to use all columns from sheet.

Example using your advice is A1 to A20 but I don’t want A6 & A16 to be part of it.
 
Upvote 0
Then you'll need to loop through the range and build the array from the values you want to include
 
Upvote 0
Then you'll need to loop through the range and build the array from the values you want to include
Thats what i need the help with.

Can it not be like a list on the sheet like so.
Me.txtNotes.Value = ws.Range("Q" & rw).Value

The followed by the others i wish to use
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top