Variable undefined easy prob missing something simple

KORKIS2

Board Regular
Joined
Jun 5, 2015
Messages
143
Somethings wrong here cant figure out what can anyone help

Dim AA As Long
Dim AB As Long


AA = Worksheets("Dipole Scratchpad 1").Cells(1, "L").Value


AB = Worksheets("Dipole Scratchpad 1").Cells(1, "M").Value
MsgBox (AA)
MsgBox (AB)


Range(AA.AB - 1).Sort Key1:=Range("B7"), Order1:=xlAscending, Header:=xlGuess
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
So, what exactly is in cells L1 and M1?

And what exactly are you trying to do with "AA.AB - 1"?
That definitely does not look like a valid range reference (there shouldn't be any periods in range references).
 
Upvote 0
Just numbers like 9 and 20 they are the row values after a search for specific row in a column to find the range that needs to be alphabetically arranged. in the column I had it as (AA & AB-1) and that worked once and then it said that needed to declare a global variable
 
Upvote 0
If they are row numbers you'd need Range(AA & ":" & AB - 1) to get a valid reference.
 
Upvote 0
So if AA = 9 and AB = 20 (AB-1 = 19)

And your intention is to do this with those variables
Range("9:19").Sort Key1:=Range("B7"), Order1:=xlAscending, Header:=xlGuess

That syntax would be
Range(AA & ":" & AB - 1).Sort Key1:=Range("B7"), Order1:=xlAscending, Header:=xlGuess
 
Upvote 0

Forum statistics

Threads
1,203,502
Messages
6,055,774
Members
444,822
Latest member
Hombre

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