I need help with my VBA code which is not working. I am trying to use the following VBA code to sort my
database based on a particular column – i.e. column B:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target(1, 1), Range("A:L")) Is Nothing Then
Range("A:L").Sort Key1:=Range("B6"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
My database has 12 columns (A to L). The first 5 rows take up the headings – with all the headings formatted the way we
require them. This means that – for some of the row headings, some of the cells are merged; the heading cells are not all
equal in size. However, from Row 6 – the row from which we start entering data, all the cells are of the same size.
We use Excel User form to enter data onto the database. This is working OK.
The problem is with the
sorting of the database based on column B (which contains Names of members). The first data entry row is Row 6 and the cell
containing the first name is B6. In order to run the sort code, I right-clicked the sheet name (at the VBA editor) and pasted
the code. But it does not seem to work. At some point, it comes up with an error message as follows:
operation requires the merged cells to be identically sized)."
I need help on what I should do to get the code to
work. We require the database heading rows (rows 1 to 5) to remain the way they are – formatted. Please is there anything I
can do so that upon clicking the ‘Add Data’ command button on the user form, the data will be added to the database and
the sort code will run automatically and sort the database based on column B (not minding the fact that the cells making up
the headings in rows 1 to 5 are not identically sized.
I have attached an abridged copy of the database (zip
Thanks for your anticipated help.