How to do one simple work with macro

papita

New Member
Joined
Jan 25, 2012
Messages
32
Hi all,
In the sheet, I have data like this where I want to add term "case" using macro. How can I do. If number is one(WBC test), then in stead of No cases, No case will come But it will skip where existed one is there(DC test)

Elisa test in=3
HIv test observed in =4
DC test=No cases
WBC test=1

Output:---
Elisa test in=3 cases
HIv test observed in =4 cases
DC test=No cases
WBC test=1 case
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
This will update the selected cells.

Code:
[color=darkblue]Sub[/color] Add_Case_Terms()

    [color=darkblue]Dim[/color] cell [color=darkblue]As[/color] Range
    
    Application.ScreenUpdating = [color=darkblue]False[/color]
    
    [color=darkblue]For[/color] [color=darkblue]Each[/color] cell [color=darkblue]In[/color] Selection
        [color=darkblue]If[/color] cell.Value [color=darkblue]Like[/color] "*=[2-9]" [color=darkblue]Then[/color]
            cell.Value = cell.Value & " Cases"
        [color=darkblue]ElseIf[/color] cell.Value [color=darkblue]Like[/color] "*=##" [color=darkblue]Then[/color]
            cell.Value = cell.Value & " Cases"
        [color=darkblue]ElseIf[/color] cell.Value [color=darkblue]Like[/color] "*=1" [color=darkblue]Then[/color]
            cell.Value = cell.Value & " Case"
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]Next[/color] cell
    
    Application.ScreenUpdating = [color=darkblue]True[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Thanks AlphaFrog,
but this macro is not working properly. For somedata it is working.
Suppose I have the update the data only in H column. How can I do.
If the number of records are more than 10 or 1000, is there any solution to update
 
Upvote 0

Forum statistics

Threads
1,211,798
Messages
6,104,036
Members
447,891
Latest member
Edson Santos 294

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