Hi Jack,
To check if an entire row is selected in VBA, you can use the following code:
Formula:
If Selection.Rows.Count = 1 And Not Intersect(Selection, ActiveSheet.UsedRange) Is Nothing And Selection.Cells(1, 1).Row 1 And Selection.Cells(1, 1).Row < 43 Then
'Your code here
End If
Let me explain what each part of the code does:
- Selection.Rows.Count = 1: This checks if only one row is selected. If more than one row is selected, this condition will not be met.
- Not Intersect(Selection, ActiveSheet.UsedRange) Is Nothing: This checks if the selected row(s) intersect with the used range of the active sheet. If the selected row(s) are outside the used range, this condition will not be met.
- Selection.Cells(1, 1).Row 1 And Selection.Cells(1, 1).Row < 43: This checks if the first cell of the selected row(s) is between row 2 and row 42 (since you mentioned rownumber 1 and rownumber < 43).
By combining these conditions with the "And" operator, you can check if the entire row is selected and if the row number is within the specified range.