I have a VBA code, which is connected to a userform
The code searches the column headlines and fills in the columns with these headlines by taking the values from the userform
My question is: How can I avoid the repetition of the code?
Dim intBB As Integer
Dim rngBB As Range
intBB = 1
Do While ActiveWorkbook.Worksheets("Sheet1").Cells(1, intBB) <> ""
If ActiveWorkbook.Worksheets("Sheet1").Cells(1, intBB).Value = "Block" Then
With ActiveWorkbook.Worksheets("Sheet1")
Set rngBB = .Range(.Cells(1, intBB), .Cells(1, intBB))
End With
Exit Do
End If
intBB = intBB + 1
Loop
ActiveWorkbook.Worksheets("Sheet1").Range(Cells(2, intBB), Cells(LastRow, intBB)).Value = BlockBox.Value
intBB = 1
Do While ActiveWorkbook.Worksheets("Sheet1").Cells(1, intBB) <> ""
If ActiveWorkbook.Worksheets("Sheet1").Cells(1, intBB).Value = "HPL" Then
With ActiveWorkbook.Worksheets("Sheet1")
Set rngBB = .Range(.Cells(1, intBB), .Cells(1, intBB))
End With
Exit Do
End If
intBB = intBB + 1
Loop
ActiveWorkbook.Worksheets("Sheet1").Range(Cells(2, intBB), Cells(LastRow, intBB)).Value = HPLBox.Value