Using Range & Rowscount

DataBlake

Well-known Member
Joined
Jan 26, 2015
Messages
781
Office Version
  1. 2016
Platform
  1. Windows
Code:
 Dim lastRow As Long
 destrow = Sheets("Master Wheel").Range("A" & Rows.Count).End(xlUp).Row
 
    Columns("T:T").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove

    Range("T2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(ISERROR(VLOOKUP(RC[-19],'Master Wheel'!R1:R1048576,1,FALSE)),""err"",""delete"")"
    lastRow = Range("A" & Rows.Count).End(xlUp).Row
    Range("T2").AutoFill Destination:=Range("T2:T" & lastRow)
    
    Columns("T:T").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Cells.Select

    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("WheelPros").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("WheelPros").Sort.SortFields.Add Key:=Range( _
        "T2:T" & lastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("WheelPros").Sort
        .SetRange Range("A1:XF1000000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
    Columns("T:T").Select
    Selection.Find(What:="err", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
        
    ActiveCell.EntireRow.Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Master Wheel").Select
    Range("A" & destrow).Select
    ActiveSheet.Paste

Hey so i have this code that i'm trying to make work.
Everything is fine unless there is only 1 item in column T
for that reason i'm trying to figure out how i can get the range from the activecell "err" (row)
to the bottom of rows.count

Code:
Range(selection, Rows.Count)).select
gives me an error

any help would be appreciated
 
You are welcome.

Yes, there are multiple ways to do it. Just note that the syntax is a little different.
When in doubt, you can turn on the Macro Recorder, record yourself selecting the multi-row ranage, and see what that recorded code looks like.
Then, just build that reference in VBA.
 
Last edited:
Upvote 0

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
You are welcome.

Yes, there are multiple ways to do it. Just note that the syntax is a little different.
When in doubt, you can turn on the Macro Recorder, record yourself selecting the multi-row ranage, and see what that recorded code looks like.
Then, just build that reference in VBA.

attempted that but selecting the range in macro recorder just gave me the specific range & not the lastrow:currentrow range
it makes perfect sense now that i know i can combine things with quotations like that
 
Upvote 0
Right, those are just variables. Basically, you use the Macro Recorder to record an example of the reference you are trying to build.
Then, you build it by combining variables with literal text values.
Just remember that all literal text values need to be enclosed in double-quotes, and variables CANNOT be enclosed in double-quotes, and you can combine all the pieces using ampersands (&).
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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