Copy cell value within a row range in a single column, if cell is not empty

alex_kos92

New Member
Joined
Jun 10, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello

I have columns H-S and some cells have a value, others are empty.
1 row contains only values in column H2 and I2 , while J2-S2 are empty. 2. row contains values from H3-O3, P3-S3 are empty.
I want values from H2 and I2 to be copied to AD2 and AD3 and H3 to be copied to AD4 and so on. So I need a macro for looking up for values within H-S columns and copy in column AD only if cell has a value, otherwise look up in the next row.

Can someone please help?

Thank you
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Welcome to the MrExcel board!

We may understand better if you give us some sample data and expected results that we can test with. The following may help:
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Hello

I have columns H-S and some cells have a value, others are empty.
1 row contains only values in column H2 and I2 , while J2-S2 are empty. 2. row contains values from H3-O3, P3-S3 are empty.
I want values from H2 and I2 to be copied to AD2 and AD3 and H3 to be copied to AD4 and so on. So I need a macro for looking up for values within H-S columns and copy in column AD only if cell has a value, otherwise look up in the next row.

Can someone please help?

Thank you
prof_mast.xlsx
HIJKLMNOPQRS
2T0871C M09470 ÆLY002 ÆLX000 P32200 T04030 M85003 ÆTD008 ÆYYY11 ÆKE100 F29601 ÆKI008 M09420 M30180 ÆRA010 P306X3 T04020 M85007 ÆTD014 ÆYYY11 ÆKE100 F29601 ÆKI010 M09420 M30180 M0940A P306Y3 T04030 M49000 M09450 P30624
3T04030 M85003 P3B000 F29525 F29521 P30990 P20002 T04020 M09450 P3B000 M09011 P20002 P30990
4T0871A M09450 P32200 P30841 T0871A M09450 P32200 P30841 T0871A M09450 P32200 P30841 T04020 M85203 F29521 F29555 F29601 M09400 P306X3 P30841 T04020 M09450 P30620 P30841 T08710 M09450 P30620 P30841 T04020 M09450 P30620 P30841
5T04020 M85003 T04020 M09450
6T04020 M09450 P306Y3 Æ00131 T04020 M00020 P32940
7T04020 M09450 P30990
8T04020 M09450 P306Y3
9T04030 M8000A F29525 P30990 P30841 T04030 M09450 P30990 P30841
10T0871A M80106 P32200 P30841 T04030 M18000 M85003 P30620 P30841 T08710 M09450 P30620 P30841 T04030 M09450 P30620 P30841 T04030 M85003 MÆ0020 P30620 P30841 T08710 M09450 P30620 P30841
11T04020 M09450 P30620 P11010
12T04020 M49000 M09450 P30990
13T0871A M09470 T04030 M09450 P306Y3 T04020 M09450 P306Y3
14T04030 M09450 Æ00361 P30840
15T04020 M85003 ÆTD013 ÆYYX30 ÆKE070 F29601 ÆKI080 M09421 M09405 ÆRF005 P3B000 P306X3 T04020 M09450 M0940A
16T04030 M09450 M54110 P30990
17T04020 M09450 M90100 P11010
18T04030 M09450 M49000 P30992
19T0871C M80106 Æ00135 Æ83200 P30620 T04030 M09450 P30620 T04030 M85003 ÆYYBR3 ÆTD055 ÆKE100 F29601 ÆKI002 M09400 P306Y3 Æ83200 P32940 T04020 M09450 P306Y3 Æ00131
20T04030 M09450 M49000 P30990 P30841
21T0871A M09470 P32200 T0871A M09470 P32200 T04030 M18000 M09451 P306X3 T04030 M09450 P30620 T04030 M09450 P30620
22T04020 M09450 P30624 T08711 M09470 ÆLY013 P30620
23T04030 M09450 T04030 M85002 T04030 M85003 M85002 T04030 M85003 M85002 T04030 M85003 M85002 T08710 M09450 T08710 M80106
24T04020 M80103 P30990 T04020 M09450 M09013 P30990
25T04030 M80103 ÆKE050 F29555 F29601 P30990 T04030 M49000 M09450 P30990
26T04030 M85003 ÆTD016 ÆYYY13 ÆKE055 ÆKI080 F29601 ÆRA006 P306X3 P32940 T0871C M09450 T04030 M09450 P30624
27T04030 M49060 M09450 P30990
28T04020 M09450 M30181 MÆ0024 P30990 P01535
29T04030 M09450 P306X3
30T04030 M09450 P30620
31T04020 M80103 M85203 F29521 F29601 P30990 T04020 M09450 M00100 P30990 T04020 M80103 M85203 F29521 F29601 P30990
32T04020 M09450 P30620 P32200 T04020 M84803 F29601 P306Y4 M09400
Profylaktisk mastektomi

prof_mast.xlsx
ABACAD
1profmast_svardatomattype tekstsnomed
223-06-2014Hist. store
323-06-2014Hist. store
423-06-2014Hist. store
523-06-2014Hist. store
615-03-2000Hist. små
715-03-2000Hist. små
817-03-2009Hist. store
917-03-2009Hist. store
1017-03-2009Hist. store
1117-03-2009Hist. store
1217-03-2009Hist. store
1317-03-2009Hist. store
1417-03-2009Hist. store
1513-02-2004Hist. store
1613-02-2004Hist. store
1719-03-2019Hist. store
1819-03-2019Hist. store
1910-09-2003Hist. små
2031-01-2008Hist. store
2112-05-2009Hist. små
2212-05-2009Hist. små
2301-07-2009Hist. store
2401-07-2009Hist. store
2501-07-2009Hist. store
2601-07-2009Hist. store
2701-07-2009Hist. store
2801-07-2009Hist. store
2911-04-2019Hist. store
3016-03-2020Hist. små
3108-02-2011Hist. store
3208-02-2011Hist. store
3308-02-2011Hist. store
3418-01-2010Hist. store
3530-06-2015Hist. store
3630-06-2015Hist. store
3723-11-2016Hist. små
3810-11-2021Hist. store
3924-01-2017Hist. små
4026-07-2017Hist. store
Profylaktisk mastektomi
 
Upvote 0
Welcome to the MrExcel board!

We may understand better if you give us some sample data and expected results that we can test with. The following may help:
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
Hello

I have done that, this is only a part of it for example.
As you can see, H2-K2 have values. AD2-AD5 have the same date, because they are from the same sample. I need H2 in AD2, I2 in AD3, J2 in AD4, and K2 in AD5. L2-S2 are empty, so the macro needs to look up in H3 to fill in AD6. And so on.

Thanks you
 
Upvote 0
Welcome to the MrExcel board!

We may understand better if you give us some sample data and expected results that we can test with. The following may help:
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
Hi again

Here is what I expect in a new sheet

prof_mast.xlsx
ABCDEFGHIJK
1snomedprofmast_svardatomattype tekstsnomed
2T0871C M09470 ÆLY002 ÆLX000 P32200 T04030 M85003 ÆTD008 ÆYYY11 ÆKE100 F29601 ÆKI008 M09420 M30180 ÆRA010 P306X3 T04020 M85007 ÆTD014 ÆYYY11 ÆKE100 F29601 ÆKI010 M09420 M30180 M0940A P306Y3 T04030 M49000 M09450 P3062423-06-2014Hist. storeT0871C M09470 ÆLY002 ÆLX000 P32200
3T04030 M85003 P3B000 F29525 F29521 P30990 P20002 T04020 M09450 P3B000 M09011 P20002 P3099023-06-2014Hist. store T04030 M85003 ÆTD008 ÆYYY11 ÆKE100 F29601 ÆKI008 M09420 M30180 ÆRA010 P306X3
4T0871A M09450 P32200 P30841 T0871A M09450 P32200 P30841 T0871A M09450 P32200 P30841 T04020 M85203 F29521 F29555 F29601 M09400 P306X3 P30841 T04020 M09450 P30620 P30841 T08710 M09450 P30620 P30841 T04020 M09450 P30620 P3084123-06-2014Hist. store T04020 M85007 ÆTD014 ÆYYY11 ÆKE100 F29601 ÆKI010 M09420 M30180 M0940A P306Y3
523-06-2014Hist. store T04030 M49000 M09450 P30624
615-03-2000Hist. småT04030 M85003 P3B000 F29525 F29521 P30990 P20002
715-03-2000Hist. små T04020 M09450 P3B000 M09011 P20002 P30990
817-03-2009Hist. storeT0871A M09450 P32200 P30841
917-03-2009Hist. store T0871A M09450 P32200 P30841
1017-03-2009Hist. store T0871A M09450 P32200 P30841
1117-03-2009Hist. store T04020 M85203 F29521 F29555 F29601 M09400 P306X3 P30841
1217-03-2009Hist. store T04020 M09450 P30620 P30841
1317-03-2009Hist. store T08710 M09450 P30620 P30841
1417-03-2009Hist. store T04020 M09450 P30620 P30841
Ark1
 
Upvote 0
Good to hear you got the solution, and thanks for letting us know.

If you would like to post the solution then it is perfectly fine to mark that post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0

Forum statistics

Threads
1,214,539
Messages
6,120,100
Members
448,944
Latest member
SarahSomethingExcel100

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