1

I am creating a basic data collect form with 10 textboxes and adding to a new sheet called Database. I have couple of options like Save, Reset, Delete, Exit Form, Search and Modify.

My file works perfectly in my system as well as in other systems. But when I am running this in Office365 and in some other version of excel, I am getting the below error:

Run-time error "380", Could not set the RowSource property. Invalid property value

When I debug I found that when I am initializing my form, I am resetting it. Below is the code for reset sub.

Sub Reset()
Dim iRow As Long
iRow = [Counta(Database!A:A)] 'Identifying last row
With frmForm
.txtVendor.Value = ""
.txtAddress.Value = ""
.txtPOC.Value = ""
.txtEmail.Value = ""
.txtContact.Value = ""
.txtSpecialization.Value = ""
.txtBand.Value = ""
.txtBU.Value = ""
.txtYear.Value = ""
.txtRemark.Value = ""
.txtSearch.Value = ""
.lstDatabase.ColumnCount = 13 'As we have total 13 columns/data to populate
.lstDatabase.ColumnHeads = True 'Our database has headers
.lstDatabase.ColumnWidths = "40,95,125,85,85,85,95,50,85,40,120,70,70"

If iRow > 1 Then
.lstDatabase.RowSource = "Database!A2.M" & iRow
Else
.lstDatabase.RowSource = "Database!A2.M2"
End If
End With 
End Sub

The error is getting triggered in below line for both else or if part:

for if part

.lstDatabase.RowSource = "Database!A2.M" & iRow

for else part

.lstDatabase.RowSource = "Database!A2.M2"

I tried changing the source as below but still getting the same error:

.lstDatabase.RowSource = Sheets("Database").Range("A2:M").Address (external:=true)

ZygD
  • 22,092
  • 39
  • 79
  • 102
  • What if you try `A2:M" & iRow`? – AcsErno Aug 02 '21 at 07:48
  • Your Range addresses are invalid. You need to use the ":"-character to separate the first and second cell of the range: `"Database!A2:M" & iRow`. - `Range("A2:M")` is also invalid as `M` is not a cell, you need to add the row. – FunThomas Aug 02 '21 at 07:48
  • `Counta(Database!A:A)` can give you `0` if there is no data. See [How to find the last row](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba). Try this. Replace `iRow = [Counta(Database!A:A)] 'Identifying last row` with `iRow = Sheets("Database").Range("A" & Sheets("Database").Rows.Count).End(xlUp).Row` – Siddharth Rout Aug 02 '21 at 07:57
  • Thank you @AcsErno, @FunThomas and @Siddharth Rout. The issue was I wrote `A2.M" & iRow`. It was somehow working on the other system and I thought that's the right code. Now when I changed back to `A2:M" & iRow` it's working now. – Ashutosh Parida Aug 03 '21 at 13:03

0 Answers0