Solved

Excel Function

Posted on 2011-03-10
15
348 Views
Last Modified: 2012-05-11
A     B     C     D
1     6     1
2     4     2
3     9     --
4     7     4
5     8     --
6     1     6
7     5     --
I need to create a function in column D that looks at column C.  If C contains an integer, move to the next.  When it encounters "--", write the value found in column A in column D, but I dont wan't it to skip lines.  Is this possible?  When working, it would look like this:

A     B     C     D
1     6     1     3
2     4     2     5
3     9     --    7
4     7     4
5     8     --
6     1     6
7     5     --
0
Comment
Question by:darrennelson
  • 4
  • 3
  • 2
  • +4
15 Comments
 
LVL 25

Expert Comment

by:Fred Marshall
ID: 35096992
Lets' make sure we understand the example:

From the words I think that A3 being "3" should yield "3" in column D... but it doesn't.
Also rows A1 and A2 don't seem to have the right values in column D.

From the words it seems you'd expect this:
A     B     C     D
1     6     1     3
2     4     2     5
3     9     --    3
4     7     4
5     8     --
6     1     6
7     5     --

but from here I'm unsure because I don't know what you mean by "don't want to skip lines"  Which lines?  Input or output.  etc.
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35097013
darrennelson: Would a vba code help?

Sid
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 35097061
A simple way is to add a filter.
After that, in the column C filter, select just the "-"
then copy column A
remove the filter in column C
then paste the data into column D
0
 
LVL 50

Accepted Solution

by:
barry houdini earned 250 total points
ID: 35097078
You could use this formula in D1

=IF(ROWS(D$1:D1)>COUNTIF(C$1:C$100,"--"),"",INDEX(A$1:A$100,SMALL(IF(C$1:C$100="--",ROW(A$1:A$100)-ROW(A$1)+1),ROWS(D$1:D1))))

confirmed with CTRL+SHIFT+ENTER and copied down....it shows blanks when --s are exhausted, see attached

regards, barry
26877876.xls
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 35097082
Here is an array formula approach, enter with Ctrl+Shift+Enter:

=IF(ROWS(D$1:D1)<=COUNTIF($C$1:$C$7,"-"),INDEX($A$1:$A$7,SMALL(IF($C$1:$C$7="-",ROW($A$1:$A$7)-ROW($A$1)+1),ROWS(D$1:D1)),1),"")
0
 

Author Comment

by:darrennelson
ID: 35097106
vb code would be fine

by not skipping lines, i mean this.  A vlookup could yeild this:

A     B     C     D
1     6     1    
2     4     2    
3     9     --    3
4     7     4
5     8     --    5
6     1     6
7     5     --    7

The extra step im looking for is to pull the values in column D up without blank rows between.  RSP eluded to using a filter.  Are the same results achievable with a function or vb code?

0
 
LVL 22

Expert Comment

by:rspahitz
ID: 35097110
wow!  you two must have tapped into the same master brain for that solution :)
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 9

Expert Comment

by:McOz
ID: 35097111
You could use an array formula in column D something like this:

=IFERROR(SMALL(IF(C1:C25<>"--","",A1:A25),ROW()-1),"")

ctrl+shift+enter to commit. The disadvantage is that you need to decide up front how many rows of original data you will not exceed. (In this case, 25 rows)

Good luck!
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 35097132
darren, you could take the steps I gave and make a vba procedure for that.
you could also make a function but it appears that barry and stephen gave you one that should work without VBA :)
0
 
LVL 25

Expert Comment

by:Fred Marshall
ID: 35097134
Apparently the last example was something you *don't* want?
Please clarify by answering my original question.  Then maybe you will get better help.
An example would help.

In your first example there's a "7" in col D.  In my example there was a "3".  So, there's clearly a typo or a misunderstanding.
0
 
LVL 25

Expert Comment

by:Fred Marshall
ID: 35097140
Never mind.  I get it now.  wait a sec...
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35097165
darrennelson: Would you still like a VBA code since you have got a formula to do what you want I guess?

Sid
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 35097182
rspahitz: it might look impressive, but that exhausts my repertoire of array formulae.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 35097232
The formula is probably a good way to go.  However,if you want to replicate my filtering with a procedure, this might do it:
Sub AddDashValues()
    Range("C1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$D$8").AutoFilter Field:=3, Criteria1:="-"
    Range("A2:A999").Select
    Selection.Copy
    Range("D2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveSheet.Range("$A$1:$D$8").AutoFilter Field:=3
End Sub

Open in new window

0
 

Author Closing Comment

by:darrennelson
ID: 35097463
perfect
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
Trying to figure out group policy inheritance and which settings apply where can be a chore.  Here's a very simple summary I've written which might help.  Keep in mind, this is just a high-level conceptual overview where I try to avoid getting bogge…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now