For each cell Operation Fail

jamec100x

New Member
Joined
Jan 17, 2022
Messages
3
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
Platform
  1. Windows
  2. MacOS
In a workbook I have 2 sheets, let's just call them S1 and S2.
There is a set range of cells, "A14:Z38" on S1 that are either empty or contain column letters (a, b, c, etc).
I'd like to write a code that loops through each cell in that range on S1 and if that cell is not empty, finds the
value in S2 of the first cell of the referenced column. I'm getting an undefined object error.

Here's my code:
dim cll as range
For Each cll In ActiveWorkbooks.Sheets("S1").Range("A14:Z38").Cells
If IsEmpty(cll.Value) = False Then
cll.Value = ActiveWorkbooks.Sheets("S2").Range(cll.Value & 1)
End If
Next cll
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
VBA Code:
dim cll as range
For Each cll In Sheets("S1").Range("A14:Z38")
If IsEmpty(cll.Value) = False Then
 code input here....
End If
Next cll
 
Upvote 0
Hi & welcome to MrExcel.
It should be ActiveWorkbook, singular not plural.
 
Upvote 0
Solution
VBA Code:
dim cll as range
For Each cll In Sheets("S1").Range("A14:Z38")
If IsEmpty(cll.Value) = False Then
 code input here....
End If
Next cll

I'm still getting the "Run-time error '424': Object Required" error with that code.
This is a part of a larger code that has multiple workbooks open. Is it possible that Excel isn't finding sheet S1?
That is why I put ActiveWorkbook in my code because I had just copied a sheet into the same workbook as S1 & S2 so I thought it should be the active workbook.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,540
Messages
6,120,106
Members
448,945
Latest member
Vmanchoppy

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