VBA Dim Range Issue

mayoung

Active Member
Joined
Mar 26, 2014
Messages
257
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I need help please. The following code works perfect as is. My problem is in the third line of code my last row varies, it is not always L468. How can this section of code be changed to work? Or do I need to go about this another way? Take note I am using wildcard in my case. Thank you in advance

VBA Code:
    Range("L2").Activate
        
                Dim rng As Range
                
                For Each rng In Range("L2:L468")
                
                Select Case True
            
                Case rng.Value Like "*MAY-WS*"
                    ActiveCell.Offset(0, 1).Formula = "MAY-WS"
                Case rng.Value Like "*MAY-WWS*"
                    ActiveCell.Offset(0, 1).Formula = "MAY-WWS"
                Case rng.Value Like "SHOP IN RNTL"
                    ActiveCell.Offset(0, 1).Formula = "SHOP IN RNTL"
                Case rng.Value Like "INTERNAL"
                    ActiveCell.Offset(0, 1).Formula = "INTERNAL"
                Case Else
                    ActiveCell.Offset(0, 1).Formula = "ERROR!"
            End Select
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
One option could be:
VBA Code:
For Each rng In Range("L2:L" & Cells(Rows.Count, 12).End(xlUp).Row)
 
Upvote 1
Solution

Forum statistics

Threads
1,215,575
Messages
6,125,628
Members
449,240
Latest member
lynnfromHGT

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