Select 2 non-adjacent rows

Ezguy4u

Active Member
Joined
Feb 10, 2010
Messages
336
Office Version
  1. 365
Platform
  1. Windows
Ok so I need a vba program that will select two non-adjacent rows and the row numbers need to be variables. Attached is an example of what I have so far. Range("2:2,4:4").Select won’t let me substitute variables for the 2 and 4. Rows(2).Select and Rows(4).Select I could substitute variables for the 2 and 4 but I don’t get 2 non-adjacent rows. Any help will be appreciated. Thanks in advance.


1633558728844.png




Sub Select1()
Dim N As Integer
Dim M As Integer

Range("2:2,4:4").Select

N = 2
M = 4

Rows(N).Select
Rows(M).Select

End Sub
 
There is a lot to unpack here for me, someone who wants to learn as much as I can. I am definitely copying all these examples and saving them to my tool box. Thank you everyone for sharing your knowledge.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,214,805
Messages
6,121,656
Members
449,045
Latest member
Marcus05

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