VBA Excel365 - Need to find the last merged cell in a column

danter1972

New Member
Joined
Aug 27, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
in a sheet I have column A with merged rows in groups of 7 rows
Using VBA I want to find either:
- if the ID is already present a row: return the row number where the value is found
- if the ID doesn't exist: return the row number of the first free cell

I was using this code in another sheet without merged rows and worked fine but I cannot adapt it to function with presence of merged rows, always returns SM_lastrow=9 and (obviously) SM_emptyrow=16

If Not IsError(Application.Match(ID, Range("a2:a90000"))) Then 'CHECK IF A RECORD WITH ID EXIST IN THE SHEET
SM_matchrow = Sheets("TEST").Range("A:A").Find(what:=ID, LookIn:=xlValues, lookat:=xlWhole).Row
SM_emptyrow = SM_matchrow
Else
SM_lastrow = Sheets("shipping monitor").Range("a2").End(xlDown).Row 'find last row in the column A of the sheet
SM_emptyrow = SM_lastrow + 7 'sheet has merged rows in groups of 7
End If

Thank you in advance for the support
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
For completeness of information - columns A to K have merged rows in groups of 7 - Column L to T have individual rows
the unique ID is in column A
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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