Dynamic Range based on column cell content.

Stan101

New Member
Joined
Sep 2, 2016
Messages
26
I have a spreadsheet sent to me with various data I need to separate into two chunks of data and copy each to another worksheet. I am stuck trying to get the end row of the first range and the start row of the second range. I would prefer them as two separate subs if possible. That makes it easier for me to learn from.


For the first range I need to copy column A to column H and down to the first row that has a blank cell in column B after row A.

I have tried this code but I keep screwing it up:

Code:
Sub DynamicRange()
'Best used when column length is static

Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range

Set sht = Worksheets("Stud Wall Properties")
Set StartCell = Range("A1")

'Refresh UsedRange
  Worksheets("Stud Wall Properties").UsedRange


'Find Last Row
'LastRow = sht.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row 'This is only finding the very last empty row. Not what I want.


'''''''''''THis is the part I keep screwing up. I have tried numerous things but I keep getting it wrong.
  
  
LastRow = Range("B2").End(xlDown).Offset(1, 0)
'Step 3: Select the next row down
 'Cells(LastRow, 1).Offset(1, 0).Row

'Select Range
  sht.Range("A1:H" & LastRow).Select

Also, instead of using the first row that has a blank cell in column B after row A as the location, as I mentioned above, alternatively I could use a known fixed cell content in Column A and make my range end in the row above the row that holds this fixed cell content. Let's call this fixed cell content "cookies".



The second range again needs columns A to H. The range needs to start at the row where the known fixed cell content (cookies) is located in Column A. I need to finish the range at the last used row.

I think I can handle selection the end row because I have managed that with the code above, but I have no idea how to start the dynamic range based on finding "cookies".
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
How about
Code:
Sub DynamicRange()
'Best used when column length is static

Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range

Set sht = Worksheets("Stud Wall Properties")
Set StartCell = sht.Range("A1")

'Refresh UsedRange
sht.UsedRange


LastRow = StartCell.Offset(, 1).End(xlDown).Offset(1, 0).Row
sht.Range("A1:H" & LastRow).Select
for part 1
 
Upvote 0
Thanks for your assistance, guys. But I could not get the result I need yet. I will keep trying.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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