Multiple for each loop on different ranges inside each other

CsJHUN

Active Member
Joined
Jan 13, 2015
Messages
360
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
  2. Mobile
Hi guys, i would like to identify one row on a table with multiple merged cells in multiple column. Imagine something like this:
Ashok L. 300-7 round PC v1 DFMEA control prevention új.xlsx
ABCDEFGHIJK
1Col ACol BCol CCol DCol ECol FCol GCol HCol ICol JCol K
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Munka2


to identify the row the data has to be the same in (for exapmple) col A, Col B, Col D, Col E, Col F. However Col F is not merged and should not contain merged cells, but the values within the cells could be the same, but different content of Col A, B, D, E, F. I hope that makes sense.

I started with for each loop from left to right
VBA Code:
Dim cell_a as Range, cell_b as range...
...
'assing values for identifying row
t_find_a = "blahbla1"
t_find_b = "blahbla2"
t_find_d = "blahbla3"
t_find_e = "blahbla4"
t_find_f = "blahbla5"

'now opening the another workbook where i need to identify the row
set findfile = workbook.open(t_findfile_path)
lra = range("A" & rows.count).end(xlup).row
for each cell_a in findfile.sheets(1).range("A10:A" & lra)
if cell_a_value = t_find_a then
cell_b_start = cell_a.row
cell_b_area = cell_a.mergearea.count -1
'this sould narrow the search for column b
for each cell_b in range(cells(cell_b_start, "B"), cells(cell_b_start+cell_b_area , "B")
cell_d_start = cell_b.row
cell_b_area= cell_b.mergearea.count -1
for each cell_d...
....
..
next cell_d
next cell_b
next cell_a
so finding the first column rows, then finding the 2.nd column rows, within 1st, then 3rd rows, within 2nd, .... eventualy identify the row.
Then if i have the row, i have to check the values within the cells(merged or not) if it has the same value as the original file ( from which i started the macro)#for
But still gives me errors, sometimes 400, object not valid, object error.

Any solution? What did i wrong? What is missing?
 
Last edited by a moderator:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,216,731
Messages
6,132,391
Members
449,725
Latest member
Enero1

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