Changing static to dynamic reference in a rows.Count function?

d0rian

Active Member
Joined
May 30, 2015
Messages
313
Office Version
  1. 365
Simple Q but couldn't figure this out; current code includes:

Code:
    LastRow = Cells(rows.Count, "CA").End(xlUp).row
    Arr = Split(Application.Trim(Join(Application.Transpose(Range("CA1:CA" & LastRow)))))

Except I'm constantly adding/removing columns so the static reference to column CA is no good and I want to use a dynamic reference. I named column CA "dyn_range_grab", and tried all manner of replacing the "CA" references in the code above with variations of that name, but suspect I'm getting something easy wrong. Help?
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Why not dim the columns to two variables (e.g. FirstCol & LastCol) each time you add or remove columns?
Unless you're not adding/deleting these columns in the code but instead manually outside of the code. That would require some kind of user input to let the program know what columns to look at.
 
Upvote 0
You can find the column number then use what you already have:

Code:
myCol = Range("dyn_range_grab").Column
LastRow = Cells(Rows.Count, myCol).End(xlUp).Row
Arr = Split(Application.Trim(Join(Application.Transpose(Range(Cells(1, myCol), Cells(LastRow, myCol))))))
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

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