Help with Setting Dim as Range

nwd9s

New Member
Joined
Feb 15, 2011
Messages
21
Hi All-

I am looking for your advice on why this setting vba code below is not working. The error is on the last line where I am trying to set 'Custom' as a range. Please note I have omitted non-relevant vba code:

Code:
Sheets("Future NBV").Activate
    Dim NBVColumn As Long
        NBVColumn = Cells(1, Columns.Count).End(xlToLeft).Column
    Dim NBVRow As Long
        NBVRow = Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Macro Workspace").Activate
    Dim Custom As Range
        Custom = Range(Cells(NBVRow, NBVColumn))

Again, many thanks for your prompt guidance!

Regards,
nwd9s
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Should it be?

Code:
Set Custom = Range(Cells(1, 1), Cells(NBVRow, NBVColumn))
 
Upvote 0
Thanks for the response. I am only looking for that particular cell, as it is at the end of data set that can dynamic rows and columns.

So the Dim Custom range should only be something like AF200

Thanks,
nwd9s
 
Upvote 0
Thanks for the help, I have that line working but now have issues with my formula below. I am trying to use Custom to reference the lookup area in the index formula. Would you have an idea how to correct the syntax or a better way to do this?

Just note it is the tab 'Future NBV' where the columns or rows could change based on it being updated each month. Also, I cut the formula short as the other part is not relevant and wanted to focus on this issue.

Code:
Dim Custom As Range
Set Custom = Cells(NBVRow, NBVColumn)
Range("Q5:Q" & WorkSpace).Formula = "=IF(ISERROR(INDEX(INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0),0),MATCH(TRUE,INDEX(INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0),0)>0,0)CODE]
 
Thanks,
nwd9s
 
Upvote 0
Sorry, proper code below:

Code:
Dim Custom As Range
        Set Custom = Cells(NBVRow, NBVColumn)
    Range("Q5:Q" & WorkSpace).Formula = "=IF(ISERROR(INDEX(INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0),0),MATCH(TRUE,INDEX(INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0),0)>0,0),0)+1)),0,INDEX(INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0),0),MATCH(TRUE,INDEX(INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0),0)>0,0),0))-INDEX(INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0),0),MATCH(TRUE,INDEX(INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0),0)>0,0),0)+1))"
 
Upvote 0
Sorry I'm not sure what that is meant to do. It looks like you just need the row number (which you already have) rather that the range. Or maybe it should be Custom.Address?
 
Upvote 0
Hi VoG-

The concept was for this part of the formula:

Code:
INDEX('Future NBV'!$B$3:$" & Custom & ",MATCH(B5,'Future NBV'!$A$3:$A$" & NBVRow & ",0)

Basically I have this data table called Future NBV which I update each month and I am trying to match it to a month. I have tested the formula and it is working in Excel, it is just the syntax of how to create it in the macro to auto update the index range where the data is constantly changing:

You see this part: 'Future NBV'!$B$3:$" & Custom & "

I am trying to reference the data tab, but because I update it, it changes each month. One month the range might be B3:AF200 and the next month B3:BA500, ect. I am trying to create a dim that will lookup the last row and column so my index formula will reference the entire data set.

Hopefully this makes sense, please let me know if I can provide any further clarity.

Thanks,
nwd9s
 
Upvote 0
In that case I think it should be like this

INDEX('Future NBV'!$B$3:" & Custom.Address
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

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