Run Time error '1004':

P

Prabu

Hi All,
I'm getting the following error in my macro code:

Run Time error '1004':
Application-defined or object-defined error

My Code:
Dim r, nLastRow, ii, cc, nLastNewRow, nLTempA
Sheet4.Activate
With Sheet4
With .Range("A:Z")
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.count + r.Row - 1
For ii = 2 To nLastRow
LColBTestA = "A" & CStr(ii)
If .Range(LColBTestA).Cells.Interior.ColorIndex = xlNone Then
Sheet4.Range(LColBTestA).Cells.Select
Selection.Copy
Sheet5.Activate
If Len(Sheet5.Range("A2").Value) = 0 Then
Sheet5.Range("A2").Select
Application.ActiveSheet.Paste
Else
Set cc = ActiveSheet.UsedRange
nLastNewRow = cc.Rows.count + cc.Row - 1
nLTempA = "A" & CStr(nLastNewRow + 1)
Sheet5.Range(nLTempA).Select
Application.ActiveSheet.Paste
End If
End If
Next
End With
End With

Here i'm getting error on the following line:
Sheet4.Range(LColBTestA).Cells.Select

Plz help me to complete this code.....

Thanks,
JP
 
J

Jim Thomlinson

Not too sure exactly why you need to select the range but suffice it to say
that in order to select the range you must first select the sheet.

sheet4.select
Sheet4.Range(LColBTestA).Cells.Select
 
P

Prabu

Thanks Jim, Let me try now.

Jim Thomlinson said:
Not too sure exactly why you need to select the range but suffice it to say
that in order to select the range you must first select the sheet.

sheet4.select
Sheet4.Range(LColBTestA).Cells.Select
 
P

Prabu

Again Thanks Jim. Your solution is working fine. Actually in this code i'm
checking values from one sheet which has marked in White color. Here i'm
copying them and pasting into another sheet.

Rgds,
JP
 
P

Prabu

Ian,
Already i've activated the sheet before going to select. U could see in my
code. Jim has given solution for that. Anyway thanks to u for spending time
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top