Range Reference for an Index

jwburritt

New Member
Joined
May 22, 2019
Messages
49
Office Version
  1. 365
Platform
  1. Windows
Hello: The following codes finds the last row in a table and then creates a simple numerical index starting with 1. A couple of things:

==> Is there a way to refer to column C without hard coding it so I can add and remove columns without a problem?
==> Is there a way to refer to cell C7 without hard coding it so I can add and remove rows without a problem?

I've used the named range "data_index" in another range, but can't seem to get it to solve the above.

Thank you!


============================

Sub index_fill()


Call reset

Range("C" & Rows.Count).End(xlUp).Select

Range(Selection, "C7").Select

Selection.ClearContents

Range("data_index").Offset(1, 0).Value = 1

Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False

Range("data_date").Select



End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You could name C7, say myCell. Then:
Code:
Sub index_fill()


Call Reset

Range("myCell", Cells(Rows.Count, Range("myCell").Column).End(xlUp)).Select
Selection.ClearContents
Range("data_index").Offset(1, 0).Value = 1

Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False

Range("data_date").Select



End Sub
Be careful in deleting rows that you don't delete the row myCell is in!
 
Last edited:
Upvote 0
Thanks, Joe. But any number of rows could be deleted beginning with row 7. That's why I was trying to get to C7 by offsetting from C6, which is the named range "data_index."
 
Upvote 0
Thanks, Joe. But any number of rows could be deleted beginning with row 7. That's why I was trying to get to C7 by offsetting from C6, which is the named range "data_index."
Maybe:
Code:
Range(Range("data_index").Offset(1, 0), Cells(Rows.Count, Range("data_index").Column).End(xlUp)).Select
Selection.ClearContents
Range("data_index").Offset(1, 0).Value = 1
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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