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]
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

jek40

Active Member
Joined
Jan 17, 2005
Messages
317
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
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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
 

jek40

Active Member
Joined
Jan 17, 2005
Messages
317

ADVERTISEMENT

I am getting a runtime error #13 "type mismatch" on this line.

If cell = "na"

Thanks
John
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Can you post your whole code as you have it now?
 

jek40

Active Member
Joined
Jan 17, 2005
Messages
317
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,436
Messages
5,601,656
Members
414,463
Latest member
5amhunter

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
Top