Case If help needed !!!!

jamesmev

Board Regular
Joined
Apr 9, 2015
Messages
233
Office Version
  1. 365
Platform
  1. Windows
I currently am using an "If Target.Address=Range("A2").Address Then_
Range ("J6").Value = 1

The issue is that the Procedure is too long. I have this for over 800 Rows.

How can I write this to shorted but allow an unlimited number of rows without getting the Procedure Too Large Message?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I'd recommend putting the cell values into a list. If it were short enough, you could put the list into arrays or dictionaries. With 800 rows, it would make sense to just make a list in a worksheet. For example:

AB
1A2J6
2A3J7
3H5X99
4

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet7



I built this table on Sheet7. Then I created code like this:

Code:
Sub testit(target As Range)

    wk = Evaluate("VLOOKUP(""" & target.Address(0, 0) & """,Sheet7!A1:B3,2,FALSE)")
    On Error Resume Next
    Range(wk) = 1

End Sub
It looks up the address in the table, finds the matching cell in the next column, then moves a 1 into that cell. If it is not found in the list, it will return Error 2042, and the On Error line will cause the assignment line to be skipped. There are details to iron out, but this gives the basic gist of it.
 
Upvote 0
I think the issue with this is the range is always J6.
J6 generates a number which then is indexed to generate a name associated with that number.

So once I click on the Target.Address ("A1") it will generate a number to J6 which is tied to "Sam Samson" which then shows on a different cell...
 
Upvote 0
Is this in a Selection_Change event? The same type of thing can work like this:

AB
1A21
2A32
3H53

<colgroup><col style="width: 25pxpx"><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet7



Code:
Sub testit(target As Range)

    wk = Evaluate("VLOOKUP(""" & target.Address(0, 0) & """,Sheet7!A1:B3,2,FALSE)")
    If Not IsError(wk) Then Range("J6") = wk

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,544
Members
449,169
Latest member
mm424

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