Beneindias
Board Regular
- Joined
- Jun 21, 2022
- Messages
- 120
- Office Version
- 365
- Platform
- Windows
- MacOS
Hello, Excel Wizards,
I have an excel file where I have some VBA code to create a checkbox in column B, everytime I add a row to a table.
But this code is not finished and I've been trying to improve it, but my knowledge in VBA is really limited.
So, my code is creating the checkboxes in column B and linking them to column C.
But I had to hard code the rows, because I think that the code was getting the number of the row, as the number of the row inside the table, but then, it was creating the checkbox in the same number, but considering the worksheet row, so I add to make it like "lastRow + 7", because my table starts in row number 7.
So, if someone can help me change that, so that it considers table row when creating checkbox, it would be awesome.
Next thing;
As I had the code, it was creating a checkbox in the last row everytime i made changes to the worksheet.
I tried to make a condition to check if in column B of the lastRow there was a checkbox, but it's not working and it's giving me an error, now: "Run-time error '438': Object doesn't support this property or method"
The error is in the line where I have my IF condition: " If Not Application.Intersect(Cells(lastRow, PagoColumn), ActiveSheet.CheckBoxes.TopLeftCell) Is Nothing Then"
Can anybody help me? The thing I realy need, is to check if there is a checkbox in my lastRow in column B. If a checkbox exists there, do nothing, if not, it needs to create that checkbox.
As a bonus, I would like to swap "lastRow + 7" for something that was more "dynamic" and looked for lastRow INSIDE THE TABLE.
Thanks for enyone that can help me.
I have an excel file where I have some VBA code to create a checkbox in column B, everytime I add a row to a table.
But this code is not finished and I've been trying to improve it, but my knowledge in VBA is really limited.
So, my code is creating the checkboxes in column B and linking them to column C.
But I had to hard code the rows, because I think that the code was getting the number of the row, as the number of the row inside the table, but then, it was creating the checkbox in the same number, but considering the worksheet row, so I add to make it like "lastRow + 7", because my table starts in row number 7.
So, if someone can help me change that, so that it considers table row when creating checkbox, it would be awesome.
Next thing;
As I had the code, it was creating a checkbox in the last row everytime i made changes to the worksheet.
I tried to make a condition to check if in column B of the lastRow there was a checkbox, but it's not working and it's giving me an error, now: "Run-time error '438': Object doesn't support this property or method"
The error is in the line where I have my IF condition: " If Not Application.Intersect(Cells(lastRow, PagoColumn), ActiveSheet.CheckBoxes.TopLeftCell) Is Nothing Then"
VBA Code:
Sub Checkboxes_Creation()
Dim lastRow As Long
Dim sh As Worksheet
Dim worksheet1 As String: worksheet1 = "Salarios" 'Salarios
Dim PagoColumn As String: PagoColumn = "B"
Dim StatusColumn As String: StatusColumn = "C"
Dim LastRowColumn As String: LastRowColumn = "l:l" 'Include Entire Column.
Set sh = Sheets(worksheet1)
With sh
lastRow = WorksheetFunction.CountA(Range(LastRowColumn))
End With
If Not Application.Intersect(Cells(lastRow, PagoColumn), ActiveSheet.CheckBoxes.TopLeftCell) Is Nothing Then
With sh.Range(PagoColumn & lastRow)
With sh.CheckBoxes.Add(Cells(lastRow, PagoColumn).Left, Cells(lastRow + 7, PagoColumn).Top, 10, 10)
.Caption = ""
.Locked = False
.LockedText = False
.Value = xlOff
.LinkedCell = Cells(lastRow + 7, StatusColumn).Address
End With
Call CenterCheckbox
End With
End If
End Sub
Can anybody help me? The thing I realy need, is to check if there is a checkbox in my lastRow in column B. If a checkbox exists there, do nothing, if not, it needs to create that checkbox.
As a bonus, I would like to swap "lastRow + 7" for something that was more "dynamic" and looked for lastRow INSIDE THE TABLE.
Thanks for enyone that can help me.