[VBA Help] - Logic Based Values in Cells

maddykhan

New Member
Joined
Mar 28, 2013
Messages
3
Dear All,

Apologies for the novice level of skills i have for excel which is the reason im looking to this forum for help.

First i want a suggestion that should i use a macro or not for the below mentioned task.

Now the question is i have a database which looks like



Accounts</SPAN>Jan-11</SPAN>Feb-11</SPAN>Mar-11</SPAN>Apr-11</SPAN>May-11</SPAN>June-11</SPAN>July-11</SPAN>August-11</SPAN>
40011300</SPAN>0</SPAN>1</SPAN>2</SPAN>0</SPAN>0</SPAN>0</SPAN>1</SPAN>0</SPAN>
40011313</SPAN>8</SPAN>8</SPAN>8</SPAN>0</SPAN>1</SPAN>2</SPAN>3</SPAN>0</SPAN>
40011326</SPAN>0</SPAN>1</SPAN>1</SPAN>2</SPAN>3</SPAN>4</SPAN>5</SPAN>3</SPAN>
40011339</SPAN>3</SPAN>4</SPAN>5</SPAN>6</SPAN>7</SPAN>8</SPAN>9</SPAN>10</SPAN>
40011342</SPAN>3</SPAN>4</SPAN>5</SPAN>6</SPAN>7</SPAN>8</SPAN>9</SPAN>10</SPAN>
40011355</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
40011368</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
40011371</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
40011384</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
40011397</SPAN>4</SPAN>5</SPAN>4</SPAN>5</SPAN>6</SPAN>7</SPAN>8</SPAN>9</SPAN>
40011407</SPAN>4</SPAN>5</SPAN>4</SPAN>5</SPAN>6</SPAN>7</SPAN>8</SPAN>9</SPAN>
40011410</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>1</SPAN>2</SPAN>0</SPAN>
40011423</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>1</SPAN>1</SPAN>1</SPAN>
40011436</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>1</SPAN>1</SPAN>1</SPAN>
40011449</SPAN>0</SPAN>3</SPAN>4</SPAN>3</SPAN>4</SPAN>3</SPAN>3</SPAN>1</SPAN>
40011452</SPAN>0</SPAN>1</SPAN>0</SPAN>1</SPAN>1</SPAN>1</SPAN>0</SPAN>0</SPAN>
40011465</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
40011478</SPAN>5</SPAN>4</SPAN>5</SPAN>6</SPAN>6</SPAN>4</SPAN>3</SPAN>4</SPAN>
40011481</SPAN>5</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>0</SPAN>
40011494</SPAN>1</SPAN>1</SPAN>1</SPAN>0</SPAN>1</SPAN>1</SPAN>0</SPAN>1</SPAN>
40011504</SPAN>2</SPAN>3</SPAN>4</SPAN>1</SPAN>2</SPAN>3</SPAN>4</SPAN>5</SPAN>
40011517</SPAN>4</SPAN>0</SPAN>1</SPAN>0</SPAN>1</SPAN>1</SPAN>0</SPAN>0</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL><COL><COL><COL><COL><COL><COL></COLGROUP>




Now i want to calculate the status of these accounts on monthly basis by comparing it with the last month status.


If account number delinquency status increased then "FF"
If account number delinquency status decreased then "RB"
If account number delinquency status is same then "STB"

e.g. incase of Feb-11 it should be

Accounts</SPAN>Jan-11</SPAN>Feb-11</SPAN>
40011300</SPAN> FF</SPAN>
40011313</SPAN> STB</SPAN>
40011326</SPAN> FF</SPAN>
40011339</SPAN> FF</SPAN>
40011342</SPAN> FF</SPAN>
40011355</SPAN> STB</SPAN>
40011368</SPAN> STB</SPAN>
40011371</SPAN> STB</SPAN>
40011384</SPAN> STB</SPAN>
40011397</SPAN> FF</SPAN>
40011407</SPAN> FF</SPAN>
40011410</SPAN> STB</SPAN>
40011423</SPAN> STB</SPAN>
40011436</SPAN> STB</SPAN>
40011449</SPAN> FF</SPAN>
40011452</SPAN> FF</SPAN>
40011465</SPAN> STB</SPAN>
40011478</SPAN> RB</SPAN>
40011481</SPAN> RB</SPAN>
40011494</SPAN> STB</SPAN>
40011504</SPAN> FF</SPAN>
40011517</SPAN> RB</SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL></COLGROUP>


I have a huge amount of data which means thousands of accounts with years of monthly data.

I am doing it manually by putting in simple IF formula but i wish to make it automated in a vba.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
see the sheet and formula in L2 which is copied down and to the right.

Sheet1

*ABCDEFGHIJKLMNOPQR
1Accounts11-Jan11-Feb11-Mar11-Apr11-May11-Jun11-Jul11-Aug*11-Jan11-Feb11-Mar11-Apr11-May11-Jun11-Jul11-Aug
24001130001200010**FFFFRBSTBSTBFFRB
34001131388801230**STBSTBRBFFFFFFRB
44001132601123453**FFSTBFFFFFFFFRB
540011339345678910**FFFFFFFFFFFFFF
640011342345678910**FFFFFFFFFFFFFF
74001135500000000**STBSTBSTBSTBSTBSTBSTB
84001136800000000**STBSTBSTBSTBSTBSTBSTB
94001137100000000**STBSTBSTBSTBSTBSTBSTB
104001138400000000**STBSTBSTBSTBSTBSTBSTB
114001139745456789**FFRBFFFFFFFFFF
124001140745456789**FFRBFFFFFFFFFF
134001141000000120**STBSTBSTBSTBFFFFRB
144001142300000111**STBSTBSTBSTBFFSTBSTB
154001143600000111**STBSTBSTBSTBFFSTBSTB
164001144903434331**FFFFRBFFRBSTBRB
174001145201011100**FFRBFFSTBSTBRBSTB
184001146500000000**STBSTBSTBSTBSTBSTBSTB
194001147854566434**RBFFFFSTBRBRBFF
204001148150000000**RBSTBSTBSTBSTBSTBSTB
214001149411101101**STBSTBRBFFSTBRBFF
224001150423412345**FFFFRBFFFFFFFF
234001151740101100**RBFFRBFFSTBRBSTB

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
L2=IF(C2>B2,"FF",IF<span style=" color:008000; ">(C2<b2,"rb",if<span style=" color:#0000ff; ">(C2=B2,"STB")</b2,"rb",if))

<tbody>
</tbody>

<tbody>
</tbody>
 
Last edited by a moderator:
Upvote 0
Thank you so much Venkat1926... Appreciate your help...

My mistake that maybe i didnt explain my question properly...

Actually i am doing kind of same thing currently by using IF statement in each cell...

But the problem arise when i have more scenarios than just FF,RB,STB...

like,

If its a blank after having any of above codes, account is closed "CL"

and if a account is blank and first time having a delinquency indicator like 1,2,3, ... account is New "New"

Is there anyway i can use a nested IF loop by a macro or vba or something...?



Thank you for your help!
 
Upvote 0
Just for an example...

Following scenarios may occur..

Option
Logic </SPAN>
Result </SPAN>
1</SPAN>
B2</SPAN>
=</SPAN>
Blank</SPAN>
Option 2</SPAN>
2</SPAN>
C2</SPAN>
=</SPAN>
Blank</SPAN>
Blank</SPAN>
3</SPAN>
C2</SPAN>
<></SPAN>
Blank</SPAN>
New</SPAN>
4</SPAN>
C2</SPAN>
=</SPAN>
B2</SPAN>
STB</SPAN>
5</SPAN>
C2</SPAN>
></SPAN>
B2</SPAN>
FF</SPAN>
6</SPAN>
C2</SPAN>
<</SPAN>
B2</SPAN>
RB</SPAN>
7</SPAN>
B2</SPAN>
<></SPAN>
0</SPAN>
Option 8</SPAN>
8</SPAN>
C2</SPAN>
=</SPAN>
0</SPAN>
NRM</SPAN>
9</SPAN>
B2</SPAN>
<></SPAN>
Blank</SPAN>
Option 10</SPAN>
10</SPAN>
C2</SPAN>
=</SPAN>
Blank</SPAN>
CLS</SPAN>

<TBODY>
</TBODY>
 
Upvote 0
@Venkat

When using Excel jeanie, please use the ‘Analyse range (Forum)’ field near the top left to restrict the number of formulas generated. There is generally no need to display multiple formulas that are basically the same, it just fills up the board and makes your post and the thread hard to read/navigate.

Post #2 actually only contained one formula, to be copied across and down as you described so you really only needed to show that one in L2.

You will see that I have removed the excess formulas in this case.

As it happens, your formula did not post correctly anyway so if it is still relevant, you may want to post it again, noting the information provided here.
 
Upvote 0
@maddykhan

Welcome to the MrExcel board!

Could we have another small set of dummy sample data and expected results that contains examples of all the possible situations?
If you want to post a screen shot that includes row/column information (like Venkat's) then see my signature block for suggestions.
 
Upvote 0
Peter
thank u. shall keep this in mind
No problem. Two other jeanie suggestions that you may consider.

1. Displaying gridlines makes it much clearer what cell an entry is in. For example, looking at cell H11 in your earlier screen shot, it isn't immediately clear to me whether it contains 7 or 8.

2. If you preview or edit your post, it is a good idea to re-paste the jeanie code (it is usually still on your clipboard) over the top of what you see in your reply window. Doing that will stop those asterisks appearing where empty cells should be.
 
Upvote 0
Peter
Thak you for suggestios. one learans everyday a new thing. that is the attraction of learning
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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