one line of code giving problem

jek40

Active Member
Joined
Jan 17, 2005
Messages
317
Hi
I am having trouble with this line of code. compete code is listed below.
any help with getting past this line ?

If (cell.Value)="na" Then

thanks
John



Complete code below

Dim myRange As Range, cell As Range, PasteRange As Range
'Sheets("cola data").Select
Set myRange = Range("u5:u10")

For Each cell In myRange
If Range("Ah7") <> "" Then
Set PasteRange = Range("Ah65536").End(xlUp).Offset(1, 0)
Else
Set PasteRange = Range("Ah7")
End If
If (cell.Value)="na" Then
Range(Cells(cell.Row, "y").Address, _
Cells(cell.Row, "aa").Address).Copy Destination:=PasteRange
End If
Next cell
End Sub
[/code]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I think this will do what you ask, but what are you trying to do with this. Your code doesn't write into cell AH7, so PasteRange would never change, wouldn't you be overwriting previous pasted items?

Code:
If (cell.Value) = "na" Then Range("Y" & cell.Row & ":AA" & cell.Row).Copy Destination:=PasteRange
 
Upvote 0
Thanks Hotpepper

I get a type mismatch error on this line

If (cell.Value) = "na" Then

i desire the code to paste into ah7 -- if ah7 has data then it pastes into next row below.

any other ideas

Thanks
John
 
Upvote 0
Try this:

Code:
Sub test()
Dim myRange As Range, cell As Range, PasteRange As Range
'Sheets("cola data").Select
Set myRange = Range("U5:U10")
Set PasteRange = Range("AH" & Application.WorksheetFunction.Min(7, Range("AH65536").End(xlUp).Row) + 1)

For Each cell In myRange
    If cell = "na" Then Range("Y" & cell.Row & ":AA" & cell.Row).Copy Destination:=PasteRange
Next cell
End Sub
 
Upvote 0
I am getting a runtime error #13 "type mismatch" on this line.

If cell = "na"

Thanks
John
 
Upvote 0
Hotpepper
Here is the code

thanks
John

Code:
Sub Macro1()
Dim myRange As Range, cell As Range, PasteRange As Range
Sheets("cola data").Select
Set myRange = Range("U5:U10")
Set PasteRange = Range("AH" & Application.WorksheetFunction.Min(7, Range("AH65536").End(xlUp).Row) + 1)

For Each cell In myRange
    If cell = "na" Then Range("Y" & cell.Row & ":AA" & cell.Row).Copy Destination:=PasteRange
Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,212,129
Messages
6,106,114
Members
447,996
Latest member
ANDYADAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top