ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Iterating through cells problem (https://www.excelbanter.com/excel-programming/300948-iterating-through-cells-problem.html)

heenchi[_2_]

Iterating through cells problem
 
Hi everbody!

I encounter a problem with a sub of mine. It generates a runtime error
Incompatible types in the line marked.
(This is a simplified version of the macro that generates the sam
error..)

Dim pTabell As Range
Dim id As Range

Set pTabell = Range("A6:H370")

If Union(Range("G27"), pTabell).Address = pTabell.Address Then
For Each id In pTabell.Columns(1) <----ERROR
If id.FormulaR1C1 = Range("G27").FormulaR1C1 Then
id.Offset(0, Range("G27").Column - 1).Value
Range("G27").Value
End If
Next id
End If


If I switch the For Each... line to
For Each id In Range("A6:A370") (Which is what I intend in th
previous code..)
then it works like planned.

Isn't the pTabell.Columns(1) and Range("A6:A370") addressing the sam
range?

What am I doing wrong?

/Henri

--
Message posted from http://www.ExcelForum.com


Charles

Iterating through cells problem
 
heenchi


TRy

Dim pTabell As Range
Dim id As Range

Set pTabell = Range("A6:H370")

If Union(Range("G27"), pTabell).Address = pTabell.Address Then
For Each id In pTabell <----ERROR Remove column(1)
If id.FormulaR1C1 = Range("G27").FormulaR1C1 Then
id.Offset(0, Range("G27").Column - 1).Value = Range("G27").Value
End If
Next id
End If


HTH

Charle

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 05:55 PM.

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