InfoPath 2010 getting sum for option button - infopath2010

I have a survey in which I have 2 columns.
Each question can either have the left column option button selected, or the one in the right column.
At the bottom of the 17 questions, I have the TOTAL values of each column. Each row of option buttons (left and right button are bound to the same control) has a value of 1 (left option button is selected) or 2 (right option button is selected).
I need to set rules in order to update the totals. What I have so far is:
left option button:
If optButton = 1; leftTotal = leftTotal + 1
If optButton = 2; rightTotal = rightTotal + 1
This same rule is applied to all 17 questions. Now this works if the user goes through all questions and picks one option button on the first try. But if they need to switch their answer, the rules do not subtract to properly update the respective totals.
I tried doing this:
If optButton = 1; leftTotal = leftTotal + 1, rightTotal = rightTotal - 1
But that doesn't calculate the totals correctly either.
Please help! Really hard to explain this one in proper detail.

Lets say "LeftTotal" and "Righttotal" are two fields which shows the totals at the bottom.
Set LeftTotal and RightTotal default value as 0.
Now apply 2 rules on every option button set as -
1) if optButton = 1 then LeftTotal = LeftTotal + 1
2) if optButton = 2 then RightTotal = RightTotal + 1

Related

issue with vba count

hi everyone i am having problem with the vba. I Want the division box to count the number of txt boxes is been filled for example if txtbox1 > 0 then txt.divide = txt.divide + 1 similarly if other text boxes is been used then it will keep adding 1 like if there 2 text boxes used then division value will be 2 etc
any can help?
If Trading_calculator1.txt_currency1.Value > 0 Then
Trading_calculator1.txt_divide.Value = txt_divide + 1
ElseIf Trading_calculator1.txt_currency2.Value > 0 Then
Trading_calculator1.txt_divide.Value = txt_divide + 1
End If
To test if a TextBox is empty, you can do Len(TextBox.Text) > 0. This returns TRUE when there is any text in the textbox.
You can make this dynamic by using a loop to search every control in the userform (Userform.Controls collection). This way you don't need an IF statement for every textbox individually. You can use the TypeName Function to test if the control is a "TextBox" and then check if it is not empty.
Dim TextBoxCount As Long, ctrl as Variant
For Each ctrl In Trading_calculator1.Controls
If TypeName(ctrl) = "TextBox" Then
If Len(ctrl.Text) > 0 Then TextBoxCount = TextBoxCount + 1
End If
Next
txt_divide = TextBoxCount
I solved it here's what I used:
Dim divide As Integer
divide = 0
If Trading_calculator1.txt_currency1.Value > 0 Then divide = divide + 1
If Trading_calculator1.txt_currency1.Value = "" Then divide = divide - 1
Trading_calculator1.txt_divide = divide
it worked for me
the first if statement will add one if the text box value change
the 2nd if will change it back if there is no value and return it in 0

How to add 2 jpeg pictures from excel in the same cell of a table in word document?

I am trying to add few jpeg pictures (up to 6) from excel worksheet in a table (word document), but only one appears at the end. Each time I am adding a picture it goes over the previous one. Here a part of my code with the issue:
' Filling the table
For i = 1 To iNumChem
' Column 1
wdTable.Rows(i + 1).Cells(1).Range.Text = Sheet1.Cells(a + 1 + 2 * i - 2, 5).Value
' Column 2
wdTable.Rows(i + 1).Cells(2).Range.Text = Sheet1.Cells(a + 1 + 2 * i - 2, 31).Value
' Column 3
For p = 0 To 5
If Sheet1.Cells(a + 2 * i, 5 + 2 * p).Value <> 0 Then
Sheet3.Shapes(Sheet1.Cells(a + 2 * i, 5 + 2 * p).Value).Copy
wdTable.Rows(i + 1).Cells(3).Range.PasteSpecial
End If
Next p
' Column 4
Next i
I tried to work with the properties ParagraphFormat and Move, but it didn't help.
I usually find difficult to move "the cursor" to the right position to be able to add something, especially in this case with Pictures (not Shapes) to add side by side.
Any ideas/comments are welcome.
Note: Edited after comments as I mixed the terms shape and picture!
I am trying to take pictures from Excel and add them in the same cell of a table word.
When you paste the shape it won't be in the cell, it will be anchored to it but float above it. This is just the same as in Excel where the shape floats above the worksheet and hides the cells below it.
To have the shape in the table you'll need to set the wrap type to inline, otherwise the shapes will stack up on top of each other.
With wdTable.Rows(i + 1).Cells(3).Range
.PasteSpecial
.ShapeRange(1).WrapFormat.Type = wdWrapInline
End With
EDIT:
Pictures are pasted into Word as InlineShapes. They do not stack up one on top of the other. If you attempt to paste more than one into wdTable.Rows(i + 1).Cells(3).Range each one will overwrite the last. Instead you need to declare a variable outside the loop, something like wdCellRange as Word.Range, and then use it when inserting the pictures, e.g.
Set wdCellRange = wdTable.Rows(i + 1).Cells(3).Range
With wdCellRange
.Collapse Direction:= wdCollapseEnd
.PasteSpecial
End With
You could try:
...Range.Collapse Direction:= wdCollapseEnd

Removing duplicate lines of text but have exceptions - Excel

I have some lines of text that look as below. As you can see there is a duplicate of "x1". What I want to do in Excel is remove duplicates (eg. x1) but keep the word "Title" as it counts as a duplicate and it will be removed which is something I don't want.
Title
x1
Title
x2
Title
x3
Title
x1
Title
x4
I searched all over the internet about methods some of them including "data validation" or even formulas like the one below but none of these worked. So do you have any ideas on how can this be done?
=IFERROR(LOOKUP(2, 1/((COUNTIF($A$2:$A$20, $A$2:$A$20)>1)*(COUNTIF($E$1:E1, $A$2:$A$20)=0)*(COUNTIF($C$2:$C$3, $A$2:$A$20)<>1)), $A$2:$A$20), "")
There are a few ways to deal with this I suppose but if the "Title" is always the every other row, you could simply use a do loop with a "+ 2" to determine the dups. So for example, let's assume all this data is in column A starting in row 1:
x = 2
Range("C1").Formula = "=Count(A:A)"
y = range("C1")
Cells(x,2).Formula = "=Countifs(A:A, A1)"
Range(Cells(x,2)).Copy
Range(Cells(x + 1, 2), cells(y, 2)).PasteSpecial xlPasteFormulas
Do While x <= y
If Cells(x, 2) > 1 Then
Rows(x).Delete
x = x + 1 'Add 1 since you already deleted 1 row and only need to move to the next row at this point.
Else
x = x + 2 'Add 2 to ensure you don't delete the title row
End If
Loop
I realized after searching a little further that there is no easy way to do this in Excel. And in some cases it is impossible. So I found a workaround with Sublime text which is much easier to do this.
Copy-paste the content from column A to Sublime text.
Then select the repeated content that you don't want to be removed and then ALT + F3. This will select all instances of that content.(HINT: Add one "space" before that text to avoid line merging when proceeding to deleting duplicates.
Inverse the selection to now select all the rest text/content.
Then go Edit > Permute Lines > Unique....
5 . DONE!!

changes of colums randomly of excel file randomly using libra office

I have an excel file consist of 1000x3 words. I wrote 5 rows here as an example.
Target choice1 choice2 choice3
booklet criquet nutmeg luciole
argoman border phobie liom
mouche libellule taplet luciole
abrot guêpe terrier greeca
However I know currently all the words in choice2 are correct answer, I want to randomly mix the place of choice 1 and choice 2 and choice 3 using libra office such as below:
Target choice1 choice2 choice3
booklet nutmeg criquet luciole
argoman phobie liom border
mouche taplet libellule luciole
abrot terrier guêpe greeca
I am new to excel and I don't know how to work with it. Please advice me how to do it and in advance I appreciate all the comments.
Sorry for the late reply.
You can use something like this:
Sub MixTheValues()
Dim x, y, r
Dim Words As New Collection
For x = 2 To Cells(Rows.CountLarge, "B").End(xlUp).Row
For y = 2 To 4
Words.Add (Cells(x, y).Value)
Next y
For y = 2 To 4
r = Int(Words.Count * Rnd + 1)
Cells(x, y).Value = Words(r)
Words.Remove (r)
Next y
Next x
End Sub
x starts on row 2 and goes to the last row.
y defines the columns you want to use (in this case, 2 to 4 or B to D
Note that this shuffles the answers, but because it is completely random, some of them may not move at all.
Results:

Retaining original table formatting after a 'pagebreak'

So here's the finished product, a statement of accounts with a working statement table, and an ageing analysis:
Everything works great. It basically populates itself row by row with data from another table. Here is the sample code:
j = 21 'First row on the statement of accounts workbook
For k = 1 To TSOA.ListRows.Count 'TSOA is the original data table
If Not TSOA.DataBodyRange.Rows(k).Hidden Then 'excludes the filtered entries
SOAwb.Worksheets(1).Cells(j, 4) = TSOA.DataBodyRange(k, 6) 'Debit
SOAwb.Worksheets(1).Cells(j, 5) = TSOA.DataBodyRange(k, 7) 'Credit
SOAwb.Worksheets(1).Cells(j, 1) = TSOA.DataBodyRange(k, 3) 'Date
<some other similar code goes here>
j = j + 1 'forces next row
If (j + 4) Mod 50 = 0 Then 'Increase footer, since there are only 50 rows in a page
j = j + 12 'Increase header
End If
End If
Next
So I coded in a 'somewhat' dynamic pagebreak, using the line of code:
If (j + 4) Mod 50 = 0 Then
j = j + 12 'Increase header
End If
where (j + 4) is the trigger for the footer pagebreak, Mod 50 divides (j+4) by 50 and gives you the remainder. Hence if its perfectly divisible, the result = 0.
j + 12 helps to skip past the header logos, you'll understand why in the next picture.
So the line of code basically works if you didn't care about the subsequent table formatting: ><
So does anyone know how do I continue with the previous table's formatting, ie the green and white statement table in the original page in the second page? Or is there some way to preload the table formatting in the second page (bearing in mind that not all statements need a second page). Or perhaps even tinkering about the print settings when the pagebreak triggers? Or any other creative solutions?
I have had zero experience with dealing with multiple pages using VBA, and quite frankly, I do not even know how to go about navigating between pages. I can't stress hard enough that this code is my amateur attempt to do useful things with excel, so there must be room for improvement!
Just change the page margins and the top few rows get excluded, but the manual page break is still required though!

Resources