ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range references in VB (https://www.excelbanter.com/excel-programming/373744-range-references-vbulletin.html)

MathCzyk

Range references in VB
 
I am trying to loop through rows and paste data on each row. I keep getting
an error code on this (even though it should be VERY simple)!

j=1
Sheets("Array 1").Range("A75:ES75").Copy
Sheets(Cbo_Product & "_BidformPage1").Select
Range("A" & j).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False


blah blah blah. I get the error on the Range("A" & j).select line.

Tom Ogilvy

Range references in VB
 

dim sh as Worksheet
On Error resume Next
set sh = Sheets(Cbo_Product & "_BidformPage1")
On error goto 0
if not sh is nothing then
j=1
Sheets("Array 1").Range("A75:ES75").Copy
sh.Range("A" & j).PasteSpecial _
Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False
else
Msgbox "Sheet not found"
End if

--
Regards,
Tom Ogilvy


"MathCzyk" wrote:

I am trying to loop through rows and paste data on each row. I keep getting
an error code on this (even though it should be VERY simple)!

j=1
Sheets("Array 1").Range("A75:ES75").Copy
Sheets(Cbo_Product & "_BidformPage1").Select
Range("A" & j).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False


blah blah blah. I get the error on the Range("A" & j).select line.


Nigel

Range references in VB
 
Assuming that the value of j does not overflow then the statement is
correct.
But you cannot select a cell if the sheet is protected.

You could try....
Range("A" & j)..PasteSpecial Paste:=xlPasteValues

to avoid the selects.

--
Cheers
Nigel



"MathCzyk" wrote in message
...
I am trying to loop through rows and paste data on each row. I keep
getting
an error code on this (even though it should be VERY simple)!

j=1
Sheets("Array 1").Range("A75:ES75").Copy
Sheets(Cbo_Product & "_BidformPage1").Select
Range("A" & j).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False


blah blah blah. I get the error on the Range("A" & j).select line.





All times are GMT +1. The time now is 07:36 PM.

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