How to read merged cells in Excel

Hello guys,
I’m reading customer info from a sheet but the customer names are merged with other cells in the column.

How can I attribute the customer name to all the cells of merged cells?

Currently I’m getting a blank.

Each cell of B column should give me the name rather than a blank.

thanks!

image

@KD11

When the ceels are merged ideally you will get data in only one cell and that cell usually is the first cell of the merged cells…

In your case we can see there are 3 rows for each name associated with it

You can assume the same that the name will not change till next name comes in …so follow the steps

Create a variable of type string str and give default value as string.Empty

  1. Read the data into datatable dt
  2. use a for each row indatatabe activity on dt
  3. Now inside it use if condition with IsNothing(currentrow("columnname")) andAlso String.IsNullOrEmpty(Currentrow("columnname").ToString
  4. On then side use currentrow("columnname") = str and on else side use str = currentrow("columnname").ToString

At the end of loop all the blank values will be replaced with the required values

Cheers

1 Like