Selecting cells by variable

Deadly48

New Member
Joined
Jun 14, 2006
Messages
19
Dim Var3, Var6 As Integer

Var3 = 3
Var6 = 6
'
Range("A" & Var3 & ":" & "X" & Var6).Select

The above code selects cells in a range A3 to X6

How can I modify to select a group of individual cells ie. A3, B7, C10 where 3,7,10 are the variables.

Regards
Deadly48
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi Deadly48

Please try:

Code:
Sub SelectCells()

Dim Var3 As Integer, Var7 As Integer, Var10 As Integer

Var3 = 3
Var7 = 7
Var10 = 10

Application.Union(Range("A" & Var3), Range("B" & Var7), Range("C" & Var10)).Select
End Sub

Remark: Selecting in usually a bad programming practice. Most of the times it's unnecessary and inefficient. Can you not just refer to the range?

Hope this helps
PGC
 
Upvote 0
P. S. In your post you had

Dim Var3, Var6 As Integer

This declares Var3 as Variant and Var6 as Integer. if you want both as integer:

Dim Var3 As Integer , Var6 As Integer
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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