View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Concatination error in macro

Hi Constantly,

Try replacing

Set rngToCopy = "A1:U" & LastRowUsed



with

Set rngToCopy = Range("A1:U" & LastRowUsed)


---
Regards,
Norman


"Constantly Amazed" wrote in
message ...
Hi

In order to select an area limited by the number of rows in column A that
contain data in them I was provided with the following code:

Sub Select_area()

Dim LastRowUsed As Integer
Dim rngToCopy As Range

LastRowUsed = Range("A" & Rows.Count).End(xlUp).Row

Set rngToCopy = "A1:U" & LastRowUsed

End Sub

However, when I run this I get a compelation error: type mismatch and the
debugger highlights the & in the Set rngToCopy instruction which I read as
concatinating the number returned with the U to create a range.

Can anyone explain why this has failed and more importantly how to fix it?

As always thanks for any help