VBA range not recognized

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,368
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Not sure what has happened here or what I may have done, but what I'm typing in VBA the range is not recognized. Any thoughts as to why?

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub TestThis()
    range("A1").CurrentRegion
End Sub
[/FONT]

Notice the range does not capitatlize.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
That won't work anyway....what are you trying to do ??
 
Upvote 0
Sorry, that was just a snippet. I'm running a macro to fill in a selection with random numbers with some formatting.

Notice how all the range references are lower case. The code runs, just curios why the range reference stays at lower case. Did I accidentally change a setting?

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub randomnumbers()
    
    Dim Low     As Double: Low = 1 '<<< CHANGE AS DESIRED
    Dim High    As Double: High = 20 '<<< CHANGE AS DESIRED
    Dim Rng     As range: Set Rng = range("A1").CurrentRegion
    Dim Cnt     As Long: Cnt = Selection.Columns.Count
    Dim i       As Long
    
    TurnEverythingOff
    On Error GoTo Skip
    
    For Each Rng In Selection
        Rng = Int((High - Low + 1) * Rnd() + Low)
    Next Rng
    For i = 1 To Cnt: Cells(1, i).Value = "Hdr" & i: Next i
    range("A1").CurrentRegion.Borders.LineStyle = xlContinuous
    Rows("2:2").Select
    ActiveWindow.FreezePanes = True
    ActiveWindow.DisplayGridlines = False
    Application.Goto range("A2"), Scroll:=True
    range("A2").AutoFilter
    Cells.EntireColumn.AutoFit
    range("A1", Cells(1, Columns.Count).End(xlToRight)).SpecialCells(xlCellTypeConstants).Interior.ColorIndex = 6
Skip:
    TurnEverythingOn
End Sub
[/FONT]

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub TurnEverythingOff()
    With Application
        .Calculation = xlCalculationManual
        .EnableEvents = False
        .DisplayAlerts = False
        .ScreenUpdating = False
        .DisplayStatusBar = False
    End With
End Sub[/FONT]


Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub TurnEverythingOn()
    With Application
        .Calculation = xlCalculationAutomatic
        .EnableEvents = True
        .DisplayAlerts = True
        .ScreenUpdating = True
        .DisplayStatusBar = True
    End With
End Sub[/FONT]
 
Upvote 0
Ok, gotcha......works fine for me, in terms of resorting to Proper case !!
Close and reopen maybe...never actually noticed it before on any of my projects.
 
Upvote 0
Thanks Michael. Yes I had closed and reopened but no change. I was just curios.
 
Upvote 0
Maybe somewhere in your code, you have a variable with name "range", something like:
Dim range As String
 
Upvote 0
One option as stated by Akuini is you have used Range as the name for a variable, another option is you have used it as the name for a procedure.
 
Upvote 0
Thank you both. I didn't see any variable named range, but I did see a function named range. I will have to check into this deeper after work.
 
Upvote 0
It's always best to avoid using vba keywords as names for variables or procedures as it can cause all sorts of problems.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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