I've got a question about writing data to cells in a spreadsheet.
While I can locate the row I need to input data in a Sheet, and then copy the data by stipulating the letter head of the column (eg. Column A, Column B, etc), is there anyway to write the data based on the column header (the value that I put in the first row.
My current code is as follows:
'IDENTIFY ROW FOR WRITING DATA
Dim UniqueID As Range
Dim rw As Long
Set UniqueID = Sheet1.Range("A:A").Find(What:=tboPreChangeUniqueID.Text, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False)
rw = UniqueID.Row
With Sheet1
'WRITE DATA TO SHEET
.Cells(rw, "K").Value = Me.obuPreChangeSubmit
'METRICS DATA
.Cells(rw, "L").Value = Me.cboPreChangeMetricBlocks
.Cells(rw, "M").Value = Me.cboPreChangeMetricLoadTime
.Cells(rw, "N").Value = Me.cboPreChangeMetricSubscriptions
.Cells(rw, "O").Value = Me.cboPreChangeMetricsVisitDepth
.Cells(rw, "P").Value = Me.tboPreChangeMetricsDateFrom
.Cells(rw, "Q").Value = Me.tboPreChangeMetricsDateTo
In the Sheet, the first row of column K is marked as obuPreChangeSubmit
the first row of column L is marked as cboPreChangeMetricBlocks
etc.
Ideally, instead of identifying the particular cell based on the column letter, and then writing the data to that cell, can I identify the column based on the data in the first row?
eg. instead of:
.Cells(rw, "L").Value = Me.cboPreChangeMetricBlocks
.Cells(rw, "M").Value = Me.cboPreChangeMetricLoadTime
something like:
.Cells(rw, ["cboPreChangeMetricBlocks" - this being the title of the column and the data entered in the first Row]).Value = Me.cboPreChangeMetricBlocks
.Cells(rw, ["cboPreChangeMetricLoadTime" - this being the title of the column and the data entered in the first Row]).Value = Me.cboPreChangeMetricLoadTime
Hope this makes sense and that someone can help!
Thanks
Bookmarks