A very kind person has given me some wonderful code that I have been using to add information to a named range.
I'm just missing one thing, and that is having the named range(s) selected from the userform. There is a combobox from which the user selects an option, and this then selects the correct named ranges to insert it into (it will be in two named ranges, but one is always contained within the other, eg in this example if the information the user entered was the name of a dog, the named range for it to be added to would be 'dog' which always sits inside 'mammal', if it were 'carp' it would always be in 'fish' etc).
Basically I need to dim a txtbox/cbobox value as the named range, which is "dog" in the example below.
Private Sub CmdAddpet_Click()
If Me.txtaddPetname = "" Or Me.Txtaddcolour = "" Or Me.TxtAddUnit = ""
Or Me.TxtAddvalue = "" Then
MsgBox "That's insufficient data to add a pet. Please put on the
naughty hat, and think about what you’ve done."
Exit Sub
End If
With Range("dog")
.Cells(.Rows.Count).Resize(1).EntireRow.Insert
.Cells(.Rows.Count - 1, 1).Offset(0, 0).Value = Me.txtaddPetname
.Cells(.Rows.Count - 1, 1).Offset(0, 1).Value = Me.TxtAddUnit
.Cells(.Rows.Count - 1, 1).Offset(0, 2).Value = Me.Txtaddcolour
.Cells(.Rows.Count - 1, 1).Offset(0, 3).Value = Me.TxtAddvalue
.Cells(.Rows.Count - 1, 1).Offset(0, 4).Value = Me.txtaddyear
.Cells(.Rows.Count - 1, 1).Offset(0, 5).Value = Me.txtaddreason
.Cells(.Rows.Count - 1, 1).Offset(0, 6).Value = Me.txtaddnotes
End With
End Sub
Bookmarks