Macro select a row depending on a value in a column

Luke1690

Board Regular
Joined
Jul 26, 2022
Messages
121
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Guys,

I want to select a row (A:L) depending on if there is a (1 or 2) in (j17:j87)

i have a conditional formatting set up to do this which highlights the row when a 1 or 2 is entered in j17:j87.
i want to only print the conditional formatting rule but i dont think this is an option with my version of excel....
so im going to set this code up and then add print selection to the code which should work the same.

please let me know if im going the correct way about this?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
I'm not sure if this is what you need.
With the following macro you will obtain a selection of rows as shown in the following image:

1702166425261.png

That is, it will select rows A to L if there is a 1 or a 2 in column J.

VBA Code:
Sub select_rows_v2()
  Dim c As Range, rng As Range
  
  For Each c In Range("J17:J87")
    If c.Value = 1 Or c.Value = 2 Then _
      If rng Is Nothing Then Set rng = c.Offset(, -9).Resize(1, 12) Else Set rng = Union(rng, c.Offset(, -9).Resize(1, 12))
  Next
  If Not rng Is Nothing Then rng.Select
End Sub


Regards
Dante Amor

"The eyes only see what you want to see"
"Los ojos solamente ven lo que tú quieres ver"

Mental games​
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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