Solved

Need help with an excel formula

Posted on 2014-03-05
11
275 Views
Last Modified: 2014-03-09
I need a excel formula to move data from one cell to another cell with the following condition.

If A1 = NULL then move B1 to A1 else both remain the same. The same for B1 and C1

Sample:
sample
Notice that row 7 was fine and no data moving was needed there.
0
Comment
Question by:Gerhardpet
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 10

Expert Comment

by:etech0
Comment Utility
Sounds like you would be better off with a macro. Something like:
Sub macro()
For x = 2 To ActiveSheet.UsedRange.Rows.Count
    If Cells(x, 1).Value = "" Then
        Cells(x, 1).Value = Cells(x, 2).Value
        Cells(x, 2).Value = Cells(x, 3).Value
        Cells(x, 3).Value = ""
    End If
Next
    
End Sub

Open in new window


Note: you would have to put that into a blank module in the VB Editor.
0
 
LVL 14

Expert Comment

by:DrTribos
Comment Utility
I am not sure if what you want is possible with formulas alone, at least not on the same sheet.  

Reason is that the input for the formula changes so I think you end up with a circular type of reference.

Would you be happy to have your original sheet as raw data and a 2nd sheet as corrected data?

Other wise you can definitely do it with a VBA macro Or by processing the data to additional rows and then manually deleting after copying and pasting 'without formulas'.

HTH
0
 
LVL 1

Author Comment

by:Gerhardpet
Comment Utility
I have no clue how to use a macro. How would I use it or set it up?
0
 
LVL 10

Expert Comment

by:etech0
Comment Utility
Press alt-F11 to open the VB Editor.

Click Insert > Module.

Paste the code above into the blank window that opens. Note: You should probably change the word "macro" in the code to something that describes what we're doing. EG: FixAddresses.

How to run the macro would depend on what version of excel you're using. You can tell us what version for more specific instructions, or google "run macro in excel 2010" or whatever version it is.

Good luck!
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
Comment Utility
Without a macro:

Select the column A data........In this case......A2:A4
Press F5
Click on special
Select Blanks
OK
Now right-click on one of the selected blank cells
Select delete
Select Shift cells left
Click OK
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Author Comment

by:Gerhardpet
Comment Utility
I'm using Excel 2010
0
 
LVL 13

Expert Comment

by:Santosh Gupta
Comment Utility
you can also try this.... it will move all cell to left in case of blank cell.

Sub Foo()
Lr = Range("A" & Rows.Count).End(xlUp).Row
Set Rng = Range("A1:A" & Lr)
For Each C In Rng
    If C = "" Then
    C.Delete Shift:=xlToLeft
    End If
Next C
End Sub
0
 
LVL 1

Author Closing Comment

by:Gerhardpet
Comment Utility
Syed,
Your solution worked perfect for what I wanted. Thanks for your help!
0
 
LVL 14

Expert Comment

by:DrTribos
Comment Utility
Syed - I'd have mucked around with formulas for an hour or macros for a minute to sort this, learnt something simple and new :-)  - thanks +1
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
Comment Utility
Be my guest.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
My experience with Windows 10 over a one year period and suggestions for smooth operation
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

771 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

12 Experts available now in Live!

Get 1:1 Help Now