2

I want to create a makro in Excel which performs - after pressing a button - the below. I attached some dummy data that is formatted like the actual sheet.

enter image description here

There are several data blocks that are seperated by headlines in Sheet 1. From these headlines, I want to get a string of numbers and put it into column S for each line with data below that heading. In line 6 the heading says "2000", thus lines 8-19 should have a "2000" in column S and so on. The number I want to get is always after the word "Monthlyaccount" but the lenght of the number can be different - from 1 to 7 digits. For lines where no data is given (data lines might be recognized by looking if in A is a valid date given) there should just be "ERR" instead of the number.

Can anyone help out?

Thanks so much upfront!

2
  • See How to Ask What have you attempted? Commented Jun 19, 2013 at 10:11
  • I tried to get the string using =MID but the position is always different. I can recognize which line is a headline but can't bring it on from there... Commented Jun 19, 2013 at 10:17

2 Answers 2

1

Say the string (in cell A1) contains "Monthlyaccount" followed by a blank followed by a number followed by another blank. To extract the number, use:

=--LEFT(MID(A1,FIND("Monthlyaccount",A1)+15,9999),-1+FIND(" ",MID(A1,FIND("Monthlyaccount",A1)+15,9999)))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the suggestion, but it does not quite work. In this case in outputs the word after the number for me but not the number
0

This does as requested. Paste the following into S3 and drag down

=IF(AND(ISNUMBER(RIGHT(A2,4)*1),ISNUMBER(RIGHT(A3,4)*1)),S2,IF(ISNUMBER(RIGHT(A3,4)*1),LEFT(RIGHT(A1,LEN(A1)-FIND("Monthlyaccount",A1)-14),FIND(" ",RIGHT(A1,LEN(A1)-FIND("Monthlyaccount",A1)-14))),"ERR"))

1 Comment

It does not look bad as it says ERR in the 3 heading rows but then the cells remain empty, so it does not work completly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.