CustomX
CustomX

Reputation: 10113

Excel macro - counting inserted rows

I'm copying data from one sheet to another and I have a universal counter, x.

    x = 2
    Sheets("Info").Select
    Range("B2:B6").Copy Destination:=Sheets("GreatIdea").Range("A" & x)
    x = x + 1

So I insert 5 rows and the following fields get data; A2, A3, A4, A5, A6.

    x is currently 3
    Sheets("Info").Select
    Range("B10").Copy Destination:=Sheets("GreatIdea").Range("A" & x)

So now 1 row gets inserted, but cell A3 will get its data overwritten. How can I add 'x' up with the number of fields added in the previous copy. So 'x' becomes 7?

Many thanks!

Upvotes: 0

Views: 549

Answers (1)

Dave
Dave

Reputation: 3448

You can use Rows.Count

x = x + Range("B2:B6").Rows.Count

Upvotes: 1

Related Questions