Replace Rows("2:48").Select to Rows(Range)

FJSeminario

New Member
Joined
Mar 26, 2011
Messages
12
I want to be able to select a range of rows to sort, but I don't know the
number of rows in the Sheet, so I find out programmatically first and then
move to the Range object Frm_sortRange01
I am getting a type mistmatch where it is indicated by the Comment
on the right of the statement


Option Explicit
Option Base 1

Dim GeoCodeTableStartRow As Integer
Dim Frm_SortRange01 As Range

GeoCodeTableStartRow = 2

'
Set Frm_SortRange01 = Range("2:48") ' <===== Is this correct?

ThisWorkbook.Activate
Sheets("GeoCodeTable").Activate
Sheets("GeoCodeTable").Select

' I got this code from recording a Macro in Excel
Changed code to automate Original Code
Rows(Frm_SortRange01).Select ' Rows("2:48").Select
' Process stops with Type mistmach
Application.CutCopyMode = False
Selection.Sort Key1:= _
Range("A2"), ' Range ("A" & GeoCodeTableStartRow), _
Order1:=xlAscending, Key2:= _
Range("C48"), ' Range("C" & GeoCodeTableStartRow) _
, Order2:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal
<input id="gwProxy" type="hidden"><!--Session data--><input *******="if(typeof(jsCall)=='function'){jsCall();}else{setTimeout('jsCall()',500);}" id="jsProxy" type="hidden">
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You could try the following to ensure the variable is more clearly defined.

Code:
Dim Frm_SortRange01 As Excel.Range

Set Frm_SortRange01 = Sheets("SheetName").Range("2:48")

I presume your code is all within a subroutine? Also, do you have a user form called Frm_SortRange01? I would be inclined to rename this variable to avoid any confustion (ie rngSortRange).

D
 
Upvote 0
You could try the following to ensure the variable is more clearly defined.

Code:
Dim Frm_SortRange01 As Excel.Range

Set Frm_SortRange01 = Sheets("SheetName").Range("2:48")
I presume your code is all within a subroutine? Also, do you have a user form called Frm_SortRange01? I would be inclined to rename this variable to avoid any confustion (ie rngSortRange).

D

Tuelor, Thanks this work and I changed the name as you sugested but i had another problem, this is a duplicate Thread and there were more replies to the other one,Please refer to it for the development of that thread
http://www.mrexcel.com/forum/showthread.php?t=539046

Thanks

<input id="gwProxy" type="hidden"><!--Session data--><input *******="if(typeof(jsCall)=='function'){jsCall();}else{setTimeout('jsCall()',500);}" id="jsProxy" type="hidden">
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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