Getting rows and columns from range object

cursemyhandz

New Member
Joined
Apr 4, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have some data in a spreadsheet, and have used VBA to create a dynamic range object from this data like so:

VBA Code:
Dim ws As Worksheet
Dim rng As Range
Set ws = ThisWorkbook.Sheets("Sheet1")
Set rng = ws.Range("A1").CurrentRegion

I am new to VBA, so I don't know exactly what this range object is, but I imagine we have coordinates (x_1, y_1) and (x_2, y_2) which define a rectangle. I have a number x_3 (with x_1 < x_3 < x_2), and I want to extract y_1, x_2 and y_2 from my range object to make a new range object with coordinates (x_3, y_1) and (x_2, y_2).

Thank you! Also, I am quite new to VBA, so any resources for getting to grips with this language would be helpful.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
A "Range" object represents a cell, a row, a column, or a rectangular range of cells on a worksheet. It's not exactly defined by coordinates like (x, y) in a Cartesian plane, but rather by the addresses of its top-left and bottom-right cells. It's just like when you select a continuous range on the worksheet.

It would be helpful to share your sample data and desired output.
 
Upvote 0

Forum statistics

Threads
1,215,507
Messages
6,125,207
Members
449,214
Latest member
mr_ordinaryboy

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