View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
RPW RPW is offline
external usenet poster
 
Posts: 52
Default copy paste for each cell in an array

I'm trying to copy paste from one worksheet to another via VBA. My first
attempt resulted in an error as soon as a blank cell was encountered. So I
came up with the following code. The For...Next and If...Then work fine -
the problem is with the copy/paste lines. I'd appreciate the help (and a
little explaination so I don't gum it up again the next time). Here's the
<snipped code:

myAddresses = Array("A12:A35,A37:C48,L12:O48,L49:M56,L58:L59")
For RangeCounter = LBound(myAddresses) To UBound(myAddresses)
Set BCRange = Nothing
On Error Resume Next
Set BCRange = wsh1.Range(myAddresses(RangeCounter))
For Each cell In BCRange.Cells
If cell.HasFormula = True Then
wsh1.Range(myAddresses(RangeCounter)).Range(cell). Copy
NewWbk.Worksheets("Basic Components Pricing").Activate
wsh2.Range(myAddresses(RangeCounter)).PasteSpecial _
xlPasteFormulas
ElseIf cell.Value 0 Then
wsh1.Range(myAddresses(RangeCounter)).Range(cell). Copy
NewWbk.Worksheets("Basic Components Pricing").Activate
wsh2.Range(myAddresses(RangeCounter)).Range
_(cell).PasteSpecial xlPasteValues
Else
End If
Next cell
Next RangeCounter
--
rpw