VBA to create range name based on value of cells in the range?

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
358
Office Version
  1. 2007
Platform
  1. Windows
Hello,
I’m still working on a way to speed up recalcs of my worksheet. My current concern is creating a named range that varies depending on other data.

I have an IF formula in column P that the results change based on the status of a cell in the corresponding row in column M. The formula is copied down column P as many as 2000 rows (albeit not likely that many).

Here is a test sample of the formula in Column P:
=IF(B33="","Cat",IF(M33<=0,C33,"Dog"))

What I’m looking for is a routine to create a range name (LookupDate) that is based on the cells in column P that contain values (dates). Following is a sample screen shot of what I’m looking at. In the screen shot, I would want the LookupDate range to be the cells in column P that have a date (i.e., “P37:P43”). The range changes every time an entry is made in column M; therefore the routine would have to be run multiple times. I believe I know how/where this will be triggered.

My concern is, as time progresses more entries will be made in column M which I assume may cause the “recalc” to drastically slow down. I’m hoping I can find a way to limit the times the routine will have to be called.


1724375832076.jpeg


Any suggestions would be appreciated and thanks for viewing,
Steve K.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
with VBA you can accellerate the calculation by using arrays und the Select Case function. To set a range by cell value this litte examle may help:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True

If Target.Row = 1 And Target <> "" Then
    test Target.Column
End If

End Sub


Sub test(iCol As Integer)
Dim rng As Range, r As Integer, c As Integer

Cells.ClearFormats
Set rng = Range(Cells(1, iCol), Cells(10, iCol))
rng.Interior.Color = RGB(200, 100, 200)

End Sub

Code to a sheet
 
Upvote 0
Solution
with VBA you can accellerate the calculation by using arrays und the Select Case function. To set a range by cell value this litte examle may help:
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True

If Target.Row = 1 And Target <> "" Then
    test Target.Column
End If

End Sub


Sub test(iCol As Integer)
Dim rng As Range, r As Integer, c As Integer

Cells.ClearFormats
Set rng = Range(Cells(1, iCol), Cells(10, iCol))
rng.Interior.Color = RGB(200, 100, 200)

End Sub

Code to a sheet

Thank you SeniorNewbie for your suggestion.
I'm a bit confused as to how this should be modified. I am quite interested in how your routine may "accelerate" the process. However, I think I found a solution to my problem. I'm going to keep working on it for now. If I get lost (which is quite often), I'm sure I will be back. I'll keep this in mind once I get my other problem resolved.

Again, much appreciated,
Steve K.
 
Upvote 0
Hi Steve,
the code above accellerates nothing, but
accellerate the calculation by using arrays und the Select Case function.
grx
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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