0

I am trying to store a variable name firstRng into

lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row
Range("A"& lMaxRows + 1).Select 

in place of "A"

here is what I have tried


Dim entireRange As Range
Dim firstRng As Range
Dim secondRng As Range

Set entireRange = Range("A2:C2")
Set secondRng = Range("B2")
Set firstRng = range("A:A")

    entireRange.Select
    secondRng.Activate
    Selection.Copy
    lMaxRows = Cells(Rows.Count, firstRng).End(xlUp).Row
    Range(firstRng & lMaxRows + 1).Select
    ActiveSheet.Paste

it will error on 1maxRows "Type mismatch"

3
  • firstRng.Cells(lMaxRows + 1). Commented Nov 17, 2021 at 14:59
  • Set secondRng = Range("2") - that's not valid. Commented Nov 17, 2021 at 15:00
  • When using firstRng use Cells and not Range and use firstRng.Column to return the column number: lMaxRows = Cells(Rows.Count, firstRng.Column).End(xlUp).Row And Cells(lMaxRows , firstRng).Select Commented Nov 17, 2021 at 15:00

1 Answer 1

2

firstRng is a multi-cell Range. You're implicitly working with its .Value, and not with relevant properties such as its .Column.

You should also avoid Activate and Select:

lMaxRows = Cells(Rows.Count, firstRng.Column).End(xlUp).Row

entireRange.Copy Destination:= firstRng.Cells(lMaxRows + 1)

Or

entireRange.Copy Destination:= Cells(lMaxRows + 1, firstRng.Column)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.