Selecting individual cells

jstuexcel

New Member
Joined
Jun 14, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hello everyone!

I'm hoping there's an easy way to select individual cells besides ctrl + click.

Basically, I need to select individual cells with the TRUE value to insert a row in between them.

Other than manually selecting the relevant cells, the closest I've gotten is using ctrl + F to find all the cells I want to select (in this case, cells with TRUE) and selecting all the results.

The issue with this is that if there are two TRUE results one after another, the selection includes both, rather than each individual cell.

To show you what I mean, here is what I'm getting:
1724038535874.png


But here is what I want:
1724038572441.png

Looking forward to hearing everyone's suggestions :)
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
If you do a Find All for TRUE and select all the results, and there is at least one TRUE in a different column, the TRUE matches in your desired column will be selected individually. The only way this would be useful to you is if you put a TRUE value in some other column way below your data so it will not affect your data when you insert rows.

1724039270356.png


The other solution would be to use VBA to insert the rows. We can do that if my suggestion above doesn't work for you.
 
Upvote 0
If you do a Find All for TRUE and select all the results, and there is at least one TRUE in a different column, the TRUE matches in your desired column will be selected individually. The only way this would be useful to you is if you put a TRUE value in some other column way below your data so it will not affect your data when you insert rows.

View attachment 115596

The other solution would be to use VBA to insert the rows. We can do that if my suggestion above doesn't work for you.
Thank you for your reply :)
For some odd reason, when I try your first suggestion in my main spreadsheet it doesn't work, but in a fresh sheet it does... I've removed conditional formatting and converted from a table to range to see if that's the issue but no luck.

When you get the chance I would love to see your VBA solution.
 
Upvote 0
Change references as required.
Code:
Sub Maybe()
Dim rngVal As Range
Dim i As Long
Set rngVal = Nothing
Application.ScreenUpdating = False
    For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
        If Cells(i, 1).Value = "True" And Cells(i - 1, 1).Value = "True" Then
            If rngVal Is Nothing Then
                Set rngVal = Cells(i, 1)
                    Else
                Set rngVal = Union(rngVal, Cells(i, 1))
            End If
        End If
    Next
    rngVal.Select
    Selection.Insert Shift:=xlDown
Cells(1).Select
Application.ScreenUpdating = True
End Sub
 
Upvote 1
Change references as required.
Code:
Sub Maybe()
Dim rngVal As Range
Dim i As Long
Set rngVal = Nothing
Application.ScreenUpdating = False
    For i = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
        If Cells(i, 1).Value = "True" And Cells(i - 1, 1).Value = "True" Then
            If rngVal Is Nothing Then
                Set rngVal = Cells(i, 1)
                    Else
                Set rngVal = Union(rngVal, Cells(i, 1))
            End If
        End If
    Next
    rngVal.Select
    Selection.Insert Shift:=xlDown
Cells(1).Select
Application.ScreenUpdating = True
End Sub
Sorry I'm a VBA noob - are you able to tell me how to set a column other than A?
 
Upvote 0
Change the "A" to "L" or "M" or "Z" or whichever Column you want.
You can also change to the Column numbers, A = 1, B = 2, C = 3 etc.
Code:
Sub Maybe()
Dim rngVal As Range
Dim i As Long
Set rngVal = Nothing
Application.ScreenUpdating = False
    For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
        If Cells(i, "A").Value = "True" And Cells(i - 1, "A").Value = "True" Then
            If rngVal Is Nothing Then
                Set rngVal = Cells(i, "A")
                    Else
                Set rngVal = Union(rngVal, Cells(i, "A"))
            End If
        End If
    Next
    rngVal.Select
    Selection.Insert Shift:=xlDown
Cells(1).Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Here's an alternative macro. It is assumed that the TRUE values are the result of formulas.
VBA Code:
Sub Insert_Rows()
Dim rng As Range, area As Range, y&
On Error Resume Next
Set rng = Range([A1], Cells(Rows.Count, "A").End(3)) _
    .SpecialCells(xlCellTypeFormulas, 4) 'Change column as required
On Error GoTo 0
If rng Is Nothing Then
    MsgBox "There are no cells containing TRUE"
    Exit Sub
End If
Application.ScreenUpdating = False
For Each area In rng.Areas
    For y = area.Count To 1 Step -1
        area(y).EntireRow.Insert
    Next y
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Revised (I missed out a step) :
VBA Code:
Sub Insert_Rows()
Dim rng As Range, area As Range, y&
On Error Resume Next
Set rng = Range([A1], Cells(Rows.Count, "A").End(3)) _
    .SpecialCells(xlCellTypeFormulas, 4) 'Change column as required
On Error GoTo 0
If rng Is Nothing Then
    MsgBox "There are no cells containing TRUE"
    Exit Sub
End If
Application.ScreenUpdating = False
For Each area In rng.Areas
    For y = area.Count To 1 Step -1
        If area(y) = True Then area(y).EntireRow.Insert
    Next y
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Revised (I missed out a step) :
VBA Code:
Sub Insert_Rows()
Dim rng As Range, area As Range, y&
On Error Resume Next
Set rng = Range([A1], Cells(Rows.Count, "A").End(3)) _
    .SpecialCells(xlCellTypeFormulas, 4) 'Change column as required
On Error GoTo 0
If rng Is Nothing Then
    MsgBox "There are no cells containing TRUE"
    Exit Sub
End If
Application.ScreenUpdating = False
For Each area In rng.Areas
    For y = area.Count To 1 Step -1
        If area(y) = True Then area(y).EntireRow.Insert
    Next y
Next
Application.ScreenUpdating = True
End Sub
This worked perfectly! Thank you!
 
Upvote 0
Change the "A" to "L" or "M" or "Z" or whichever Column you want.
You can also change to the Column numbers, A = 1, B = 2, C = 3 etc.
Code:
Sub Maybe()
Dim rngVal As Range
Dim i As Long
Set rngVal = Nothing
Application.ScreenUpdating = False
    For i = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
        If Cells(i, "A").Value = "True" And Cells(i - 1, "A").Value = "True" Then
            If rngVal Is Nothing Then
                Set rngVal = Cells(i, "A")
                    Else
                Set rngVal = Union(rngVal, Cells(i, "A"))
            End If
        End If
    Next
    rngVal.Select
    Selection.Insert Shift:=xlDown
Cells(1).Select
Application.ScreenUpdating = True
End Sub
Thank you :)
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top