Help deleting rows and creating range name via VBA

EssKayKay

Board Regular
Joined
Jan 5, 2003
Messages
233
Office Version
  1. 2007
Platform
  1. Windows
I hope I can explain this properly. I have a couple questions that are somewhat related if you please.

I’m trying to create a VBA routine that deletes all consecutive rows that contain data starting in B33. The number of rows will vary from Row 33 on down to Row XXXX.

I was attempting to create a range called Data by doing a Macro Recording. In this case, it hardcodes in the last row (392). However, the next time I need to run this macro the last row may not be 392.

VBA Code:
Range("B33").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
   "=Amortize!R33C2:R392C2"
ActiveWorkbook.Names("Data").Comment = ""

Thanks,
Steve K.
 

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
if you add:
VBA Code:
LR = Cells(Rows.count, "B").End(xlUp).Row
above the top line, then replace that following code:
VBA Code:
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
   "=Amortize!R33C2:R392C2"
with:
VBA Code:
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
   "=Amortize!R33C2:R" & LR & "C2"
that will take it to the last active cell in Row B each time without having to chnage the code.
 
Upvote 0
Solution
if you add:
VBA Code:
LR = Cells(Rows.count, "B").End(xlUp).Row
above the top line, then replace that following code:
VBA Code:
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
   "=Amortize!R33C2:R392C2"
with:
VBA Code:
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
   "=Amortize!R33C2:R" & LR & "C2"
that will take it to the last active cell in Row B each time without having to chnage the code.
Thank you Dermie. This has me going in the right direction. I have more things to look at. I'm sure as this progresses I will be back but now I'm on the right path.

Much appreciated,
Steve
 
Upvote 1

Forum statistics

Threads
1,215,069
Messages
6,122,953
Members
449,095
Latest member
nmaske

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