Hello,
I am working on a code that writes labels to each row on a worksheet. The worksheet is comprised of a header row, which has a header for each category:
|ID|Category|Sub-Category|Metric|Sub-Metric|Unit|Priority|Existing Reference|Comments|Data Link|
Last row of the sheet can very depending on how much data is entered. Therefore, I want to find the number of the last filled out row on the sheet. This is the job of the first function:
I then call IdLabel(). The labels will be written in the first column "ID" I am trying to reference a cell in the first column to change the value of the cell depending on the row number.
Yet I keep getting the following error: 'object required' In addition, up in the first function, "Total" returns as 1, which is certainly not true considering I have more than 1 row of data entered in my sheet. Could anyone clarify what is happening? I am new to VBA, so I definitely have not mastered the language semantics.
I am working on a code that writes labels to each row on a worksheet. The worksheet is comprised of a header row, which has a header for each category:
|ID|Category|Sub-Category|Metric|Sub-Metric|Unit|Priority|Existing Reference|Comments|Data Link|
Last row of the sheet can very depending on how much data is entered. Therefore, I want to find the number of the last filled out row on the sheet. This is the job of the first function:
Code:
Public Sub TestIdLabel()
Total = ActiveSheet.Range("A9999").End(xlUp).Rows.Count
IdLabel (Total)
End Sub
Code:
Public Sub IdLabel(ByRef totCount As Long)
Dim rowCount, subRowCount, idCount, letterCount, marker As Integer
Dim letString, IdLabel, curCell As String
Dim rowSelect As Long
'Predefine necessary variables
idCount = 1
letterCount = 0
rowCount = 2
letString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
'Determine Name of label
IdLabel = Application.InputBox("Please specify ID Label.", "ID LABEL") + "-"
'Loops through each cell, looks at column L, if marker is present,
'id labels loop through letterCount to find appropriate ID label
Do
If ActiveSheet.Cells(rowCount, "L") = ActiveSheet.Cells(rowCount + 1, "L") Then
'Labels sub-metric "idLabel-rowCount"A,B,C,etc."" for as long as marker is present in column L
Do
'ERROR OCCURS HERE ActiveSheet.Cells("A" & rowCount).Value = IdLabel & rowCount.String & letString(letterCount)
'^^^^Eventually change so column is specified
letterCount = letterCount + 1
rowCount = rowCount + 1
Loop While ActiveSheet.Cells(rowCount, "L") <> Empty _
And ActiveSheet.Cells(rowCount, "L") = ActiveSheet.Cells(rowCount + 1, "L")
Else:
ActiveSheet.Cells(rowCount, "A") = IdLabel & rowCount.String
End If
letterCount = 1
rowCount = rowCount + 1
Loop Until rowCount = totCount
End Sub