ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Compile Error:Expected Array (https://www.excelbanter.com/excel-programming/434934-compile-error-expected-array.html)

Fatima CN

Compile Error:Expected Array
 
Hi,
I am getting an error as (Compile Error:Expected Array) when i am
running the below macro.Pls help me to debug it


Sub copyVisible()
Dim copyFrom As Range
Set copyFrom = ThisWorkbook.Sheets("Analysis").Range("C5")
Do
Set copyFrom = copyFrom.Offset(1)
Loop Until copyFrom.EntireRow.Hidden = False
copyFrom.Copy
Sheets("PG_results").Select
Selection.PasteSpecial Paste:=xlPasteValues("PG_results").Range("B5")
Application.CutCopyMode = False
End Sub





*** Sent via Developersdex http://www.developersdex.com ***

Tim Williams[_2_]

Compile Error:Expected Array
 
You can skip the copy/paste and just assign the value directly

Sub copyVisible()
Dim copyFrom As Range
Set copyFrom = ThisWorkbook.Sheets("Analysis").Range("C5")
Do
Set copyFrom = copyFrom.Offset(1)
Loop Until copyFrom.EntireRow.Hidden = False


Sheets("PG_results").Range("B5").Value = copyFrom.Value

End Sub



Tim


"Fatima CN" wrote in message
...
Hi,
I am getting an error as (Compile Error:Expected Array) when i am
running the below macro.Pls help me to debug it


Sub copyVisible()
Dim copyFrom As Range
Set copyFrom = ThisWorkbook.Sheets("Analysis").Range("C5")
Do
Set copyFrom = copyFrom.Offset(1)
Loop Until copyFrom.EntireRow.Hidden = False
copyFrom.Copy
Sheets("PG_results").Select
Selection.PasteSpecial Paste:=xlPasteValues("PG_results").Range("B5")
Application.CutCopyMode = False
End Sub





*** Sent via Developersdex http://www.developersdex.com ***




p45cal[_158_]

Compile Error:Expected Array
 

Try changing:

Sheets("PG_results").Select
Selection.PasteSpecial
Paste:=xlPasteValues("PG_results").Range("B5")
to:

Sheets("PG_results").Select
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValues
or shorter and without selecting:

Sheets("PG_results").Range("B5").value=copyFrom.va lue

not tested - (in haste).


--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?userid=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=144129



All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com