I know that there are previous posts about this subject, but I can't fathom out how to use the various solutions to fix my problem!
I have a Worksheet which is populated with new records via a UserForm - and updated by reading a record into another (similar) UserForm which is then saved back to the Worksheet ...
I've posted the code that does the (new record) Save below (the update UserForm uses similar code, but uses the existing record row number), which uses column numbers, but the problem I now have is that user requirements keep adding new columns/re-ordering the columns, which involves working through the code one-by-one every time there's a change!!!
What I'd like to do is NAME columns (I don't know whether that's possible) and then use the NAME instead of the column number - WITHOUT REFERENCING THE COLUMN NUMBER AT ANY TIME ...
Is that possible???
Many thanks ...
I have a Worksheet which is populated with new records via a UserForm - and updated by reading a record into another (similar) UserForm which is then saved back to the Worksheet ...
I've posted the code that does the (new record) Save below (the update UserForm uses similar code, but uses the existing record row number), which uses column numbers, but the problem I now have is that user requirements keep adding new columns/re-ordering the columns, which involves working through the code one-by-one every time there's a change!!!
VBA Code:
Private Sub cmdSave1_Click()
Dim m As Long
m = Cells(Rows.Count, 1).End(xlUp).Row
Cells(m + 1, 1).value = txtIncidentID
Cells(m + 1, 2).value = txtIncidentDate
Cells(m + 1, 3).value = txtIncidentTimeHours & ":" & txtIncidentTimeMins
Cells(m + 1, 4).value = txtReportedDate
Cells(m + 1, 5).value = txtReportedTimeHours & ":" & txtReportedTimeMins
Cells(m + 1, 6).value = txtReportedBy
Cells(m + 1, 7).value = cboStatus
Cells(m + 1, 8).value = cboDepartment
Cells(m + 1, 9).value = cboIncidentType
Cells(m + 1, 10).value = cboIncidentNature
Cells(m + 1, 11).value = cboIncidentFormat
Cells(m + 1, 12).value = cboNearMiss
Cells(m + 1, 13).value = cboClinicalData
Cells(m + 1, 14).value = txtIncidentSummary
Cells(m + 1, 15).value = cboDatSubjectAdvised
Cells(m + 1, 16).value = txtRemedialActionsTaken
Cells(m + 1, 17).value = txtRemedialActionsPlanned
Cells(m + 1, 18).value = txtEvidence
Cells(m + 1, 19).value = cboImpact
Cells(m + 1, 20).value = cboLikelihood
End Sub
What I'd like to do is NAME columns (I don't know whether that's possible) and then use the NAME instead of the column number - WITHOUT REFERENCING THE COLUMN NUMBER AT ANY TIME ...
Is that possible???
Many thanks ...