Range using variables

timpie_s

New Member
Joined
Feb 26, 2013
Messages
18
I am trying to set a range for autoselect sorting keeping in mind that someone (worksheet is used
by several people) is inserting colums and or rows (which would break the code and has happened
a few times):

Therefor I've created a function Kolom that retrieves the column name.
ColumnHeaders is defined as Traject!$10:$10 (10th row containing Column titles)

I've succesfully coded the firstcel as follows: (it returns $R$10) but to determine the range
using .end(xldown) until last used row in column doesn't work for me. What am i doing wrong?
Keep getting "Runtime error 1004" Method Range of Object '_Global' failed

Dim FirstCell, FilterRange As Range

FirstCell = Range(Kolom("Ploeg") & Range("ColumnHeaders").Row).Address
Msgbox FirstCell

FilterRange = Range(Range(FirstCell), Range(FirstCell).End(xlDown))
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Why aren't you using Set for the FilterRange range object?
 
Upvote 0
Assuming 'Ploeg' is the header of the column you want to find perhaps something like this.
Code:
Dim Res As Variant
  
    Res = Application.Match("Ploeg", Rows(10), 0)


    If Not IsError(Res) Then
        Set FilterRange = Range(Cells(10, Res), Cells(Rows.Count, Res).End(xlUp))
    End If

PS I'd also include worksheet references for Range/Cells to make sure the code was referring to the correct sheet.
 
Upvote 0
Thankx!
Assuming 'Ploeg' is the header of the column you want to find perhaps something like this.
Code:
Dim Res As Variant
  
    Res = Application.Match("Ploeg", Rows(10), 0)


    If Not IsError(Res) Then
        Set FilterRange = Range(Cells(10, Res), Cells(Rows.Count, Res).End(xlUp))
    End If

PS I'd also include worksheet references for Range/Cells to make sure the code was referring to the correct sheet.
 
Upvote 0

Forum statistics

Threads
1,215,516
Messages
6,125,285
Members
449,218
Latest member
Excel Master

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