Last Col in Range

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,052
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I was given this for a range from Y to the last used Col from CP in Row eRow,
VBA Code:
Set iRange = Range(Range("Y" & eRow), Range("CQ" & eRow).End(xlToLeft))
And it's worked many times fine, until suddenly iRange.address is $Y37:$CP$37
So I assumed there was a rogue invisible character somewhere and tried this
VBA Code:
                    kcol = 94
                    Do Until Val(Cells(eRow, kcol)) > 0
                    Cells(eRow, kcol) = ""
                    kcol = kcol - 1
                    Loop
                    Set iRange = Range(Range("Y" & eRow), Range("CQ" & eRow).End(xlToLeft))
Thinking that would fix it. But iRange address is still $Y37:$CP$37
What might cause this ?
 
There are several rows affected. Not sure why this should be, but here's a fix:

VBA Code:
Sub FixIt()

    With Worksheets("1990+")
        With Intersect(.UsedRange, .Range("Y:CP"))
            'xxx is something that won't be found in the range.  Change if necessary!
            .Replace What:="", Replacement:="xxx", LookAt:=xlWhole, MatchCase:=False
            .Replace What:="xxx", Replacement:="", LookAt:=xlWhole, MatchCase:=False
        End With
    End With
    
End Sub
 
Upvote 0
Solution

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Sure has... that's great. Many thanks indeed. Held me up for 3 days!
Don;t know how they got there, certainly wasn't intentional. Whatever it is.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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