Complex-ish IF statement

jamorin

New Member
Joined
Sep 27, 2008
Messages
33
Howdy folks. Here is the problem.

Three columns of data labeled Tract, Block and Lot.

What the Data to display as follows:
T#B#L# when each column has data
B#L# when there is only data in columns the Block and Lot columns
L# when there data only in the Lot Column

As you can see below, I have an IF statement that does this fine.

Where I would like some help is the next step where the combined output will only put information for the columns that apply such as:

T#L# when there is just data in the Tract and Lot columns, or
T#B# when there is only data in the Tract and Block Columns

I figure it is one more IF statement but I'm getting lost

As a bonus I'd love to know how to do it in VBA as well.

Excel Workbook
ABCDE
1TractBlockLotCombined
2537125T537B12L5
3125TB12L5
45L5
561124T611B2L4
64124116T412B41L16
71512TB15L12This one is not correct
82747TB27L47This one is not correct
910051T100B51LThis one is not correct
104623T4B62L3
Sheet1
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Maybe this? I'm saying maybe as i'm not sure how the cells you marked yellow can be incorrect if the cell I've marked green you left as correct? they look the same to me. Also is there ever a case just a T and an L?

Excel Workbook
ABCDE
1TractBlockLotCombinedFormulas
2537125T537B12L5T537B12L5
3125TB12L5B12L5
45L5L5
561124T611B2L4T611B2L4
64124116T412B41L16T412B41L16
71512TB15L12B15L12
82747TB27L47B27L47
910051T100B51LT100B51
104623T4B62L3T4B62L3
Sheet3
 
Upvote 0
With only T and L

Excel Workbook
ABCDE
1TractBlockLotCombinedFormulas
25375T537B12L5T537L5
3125TB12L5B12L5
45L5L5
561124T611B2L4T611B2L4
64124116T412B41L16T412B41L16
71512TB15L12B15L12
82747TB27L47B27L47
910051T100B51LT100B51
104623T4B62L3T4B62L3
Sheet3


Can't help with VBA but should be easy for some of the gurus on here
 
Upvote 0
Rows 7 and * are "wrong" in that "T" should not be showing up. I only what the Combined Column to to have entries if there is Corresesponding data in the Previous Columns.

Said Differently by Examples:

Tract 212, Block 3, Lot 2 would be: T212B3L2
Tract 212, Lot 2 would be: T212L2
Tract 212, Block 3 would be T212B3
Tract 212 would be: T212
Block 3 would be: B3
Lot 2 would be: L2
Block 3, Lot 2 would be: B3L2
 
Upvote 0
I believe this will do it with VBA - test in a copy of your workbook.

Code:
Dim i As Integer

i = 2

Do Until Cells(i, 1).Value="" And Cells(i, 2).Value ="" And Cells(i, 3).Value = ""
 ' Tests for values in cells to make sure there's data there

If Not Cells(i, 1).Value = "" Then
Cells(i, 4).Value = "T" & Cells(i, 1).Value 'Adds Tract Value if not Blank
End If

If Not Cells(i, 2).Value = "" Then
    Cells(i, 4).Value = Cells(i, 4).Value & "B" & Cells(i, 2).Value 'Add Block Value if not blank
    End If

If Not Cells(i, 3).Value = "" Then
    Cells(i, 4).Value = Cells(i, 4).Value & "L" & Cells(i, 3).Value ' Adds lot Value if not blank
    End If

i = i + 1 ' Next Iteration

Loop
 
Upvote 0
Correction...

Rows 7 and 8 are "wrong" in that "T" should not be showing up. I only want the Combined Column to to have entries if there is Corresesponding data in the Previous Columns. (I had correct in places I shouldn't have! doh)

Said Differently by Examples:

Tract 212, Block 3, Lot 2 would be: T212B3L2
Tract 212, Lot 2 would be: T212L2
Tract 212, Block 3 would be T212B3
Tract 212 would be: T212
Block 3 would be: B3
Lot 2 would be: L2
Block 3, Lot 2 would be: B3L2
 
Upvote 0
ret44 - I am getting a compile error. It is probably my fault. I open the VBA editor (ALT F11) and added a Module and pasted in your code.

Windows Vista Business SP2 32-bit, Office 2007
 
Upvote 0
Hi Jamorin,

What is the error?

I did not but sub tags on the code, so you would need to put

Sub Macroname() before the first line of code

and

End Sub after the last line of code

If that wasn't the issue, I may be able to help if I know the error message. It did work on my machine.
 
Upvote 0
Thanks RET - That was my issue just didn't enter it correctly. Since I have your attention, is there a way to have this run automatically everytime an entry is changed (like the IF statement does)?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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