How to Construct Auto Boolean Strings using VBA

satish78

Board Regular
Joined
Aug 31, 2014
Messages
218
Hi Friends,

I tried looking mrexcel posts and google sources for query to find VBA answer.
Here what I am looking for is:

Sheet1 ColumnA has data of boolean strings like attached in the document.
The row numbers varies every time whenever I change the data.
Boolean example has shown in image attached.

I need a VBA to do the job.
Let me know if you have questions.

 

Attachments

  • Boolean Exaampe.jpg
    Boolean Exaampe.jpg
    90.1 KB · Views: 28

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try the below code

VBA Code:
Sub findNot()

For x = 1 To ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    c = 1
    If InStr(Cells(x, 1), "NOT") > 0 Then
        For y = 1 To UBound(Split(Cells(x, 1), " "))
            c = c + Len(Split(Cells(x, 1), " ")(y - 1)) + 1
            If Split(Cells(x, 1))(y) = "NOT" Then Cells(x, 1).Characters(c, 3).Font.Color = vbRed
        Next y
    End If
Next

End Sub
 
Upvote 0
Hala Yasser ... I have added explanation after each line

VBA Code:
Sub findNot()

For x = 1 To ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row '<--- identify the range to be searched
    c = 1
    If InStr(Cells(x, 1), "NOT") > 0 Then '<--- if the cell doesn't include the word NOT then skip it
        For y = 1 To UBound(Split(Cells(x, 1), " ")) '<--- looping through each world in the cell identified by space separation
            c = c + Len(Split(Cells(x, 1), " ")(y - 1)) + 1 '<--- checking the total number of charecters in the cell, so far + 1 for the proceeding space
            If Split(Cells(x, 1))(y) = "NOT" Then Cells(x, 1).Characters(c, 3).Font.Color = vbRed '<--- checking if the word is "NOT" to color it red c=where to start coloring from & 3 # of letters of the word NOT
        Next y
    End If
Next

End Sub
 
Upvote 0
Thanks a lot for the explanation but I don't mean your code (I can get it well). I think the OP needs to construct and build strings based on the values of column A and get the desired output as in the picture. I am not sure
 
Upvote 0
My bad I didn't check the file the OP posted ?
 
Upvote 0
Thanks a lot for the explanation but I don't mean your code (I can get it well). I think the OP needs to construct and build strings based on the values of column A and get the desired output as in the picture. I am not sure
You are right YesserKhalil. I want to construct and build strings based on the values of ColumnA and get the desired output as shown in the picture.
 
Upvote 0
Can you elaborate more on how cells in column A become the desired output in column B based on your excel file & the posted picture

Boolean String (1).xlsx
AB
1DataExpected output
2JavaA and B and C and D and E and F
3pythonA and B and C and D and E and NOT F
4j2eeA and B and C and D and NOT E and F
5jspA and B and C and NOT D and E and F
6jdbcA and B and C and NOT D and NOT E and F
7jvmA and B and C and D and NOT E and NOT F
8angularjsA and B and C and NOT D and NOT E and NOT F
9html
10css
11xml
Sheet1
 
Upvote 0
Can you elaborate more on how cells in column A become the desired output in column B based on your excel file & the posted picture

Boolean String (1).xlsx
AB
1DataExpected output
2JavaA and B and C and D and E and F
3pythonA and B and C and D and E and NOT F
4j2eeA and B and C and D and NOT E and F
5jspA and B and C and NOT D and E and F
6jdbcA and B and C and NOT D and NOT E and F
7jvmA and B and C and D and NOT E and NOT F
8angularjsA and B and C and NOT D and NOT E and NOT F
9html
10css
11xml
Sheet1

Using AND NOT Operators.
 
Upvote 0
I am sorry but I'm still not able to understand ! Perhaps you can give more details of how jvm becomes A and B and C and D and NOT E and NOT F or maybe some other forum members could understand something that I am missing
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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