VBA Code running in F8 But not in F5 - vba

I am having some trouble with my vba code. It seems to be running in F8 but not in F5. When it runs in F5, item is not recognized (shows up as item = nothing). I have pasted the code below.
Sub SlicerSelect()
'On Error Resume Next
Worksheets("Sheet3").Activate
'Dim cache As Excel.SlicerCache
Dim item As SlicerItem
Dim Eval_Cell As String
Offset_Cell = Sheets("Sheet3").Range("A18").Address
A = 1: AA = 0: AAA = 0
For A = 1 To 2
AA = AA + 1
If AA = 1 Then
Slicer_Name = "Slicer_Color"
ElseIf AA = 2 Then
Slicer_Name = "Slicer_Letter"
End If
'Set cache = ActiveWorkbook.SlicerCaches(Slicer_Name)
BB = 0
Do Until End_Switch = 1
AAA = AAA + 1: BB = BB + 1: Eval_Cell = Range(Offset_Cell).Offset(0, CStr(AAA))
If BB = 1 Then
'''
Else
For Each item In ThisWorkbook.SlicerCaches(Slicer_Name).SlicerItems
If item.Name = Eval_Cell Then
item.Selected = True
Else
item.Selected = False
End If
Next item
End If
If IsEmpty(Eval_Cell) Then End_Switch = 1
Stop
Loop
End_Switch = 0
Next A
End Sub

Related

in vb.net I want to loop charts

I want listbox1 item =
aa
ab
ac
ba
bb
bc
ca
cb
cc
And this my code
Dim text As String = "abc"
Dim i As Integer = 0
Do
ListBox1.Items.Add(text.Chars(i))
i += 1
Loop Until (i = text.Length)
Use this, you need 2 loops:
For i as Integer = 0 to 2
For j as Integer = 0 to 2
ListBox1.Items.Add(text.Chars(i) & text.Chars(j))
Next
Next

Remove table border in powerpoint

The code is successfully removing table borders and is fine on screen.
While printing or print previewing, its showing some table border. How to fix it?
Sub Tableformatting ()
Dim r As Long, c As Long
Dim t As Table
Set t = ActiveWindow.Selection.ShapeRange.Table
For r = 1 To t.Rows.Count
For c = 1 To t.Columns.Count
With t.Cell(r, c)
.Borders(ppBorderTop).Transparency = 0
.Borders(ppBorderTop).Weight = 0
.Borders(ppBorderBottom).Transparency = 0
.Borders(ppBorderBottom).Weight = 0
.Borders(ppBorderLeft).Transparency = 0
.Borders(ppBorderLeft).Weight = 0
.Borders(ppBorderRight).Transparency = 0
.Borders(ppBorderRight).Weight = 0
End With
Next c
Next r
End Sub
Try using
Sub Tableformatting()
Dim r As Long, c As Long
Dim t As Table
Set t = ActiveWindow.Selection.ShapeRange.Table
For r = 1 To t.Rows.Count
For c = 1 To t.Columns.Count
With t.Cell(r, c)
.Borders(ppBorderTop).Transparency = 1
.Borders(ppBorderBottom).Transparency = 1
.Borders(ppBorderLeft).Transparency = 1
.Borders(ppBorderRight).Transparency = 1
End With
Next c
Next r
End Sub
For some reason .Transparency = 0 only works for what is actively seen, but .Transparency = 1 works for everything you asked for. It might be a bug on Microsoft's end because I don't see why this method or .Borders.Visible = msoFalse wouldn't work just for print/print preview.
Either way I hope this helped!

Nested FOR loops in VBA

I am attempting to impliment a nested FOR loop in excel. Then interior loop does not seem to be executing in the code. Is the error syntatical? What's going on here?
Sub Statistics()
Dim cc As Integer
Dim i As Integer
i = 4
cc = 0
For cc = 0 To 4
For i = 4 To -4
If Sheets("Significance").Cells(4 + cc, 13 - i) = 1 Then Sheets("Output Database").Cells(8 + currevent, 7 + cc) = i
Next i
Next cc
'Rates
i = 4
cc = 0
For cc = 0 To 4
For i = 4 To -4
If Sheets("Significance").Cells(14 + cc, 13 - i) = 1 Then Sheets("Output Database").Cells(8 + currevent, 23 + cc) = i
Next i
Next cc
End Sub
The loop referring to the i variable needs to specify that i is decreasing:
For i = 4 To -4 Step -1

problem with programming playfair cipher

I have problem with my code
Public Class Form1
Dim lm(4, 4) As Char
Dim pt As String = ""
Dim ct As String = ""
Dim key As String = ""
Dim n1, n2, n3, n4, m1, m2, m3, m4 As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
key = k.Text
key.Replace(" ", "")
pt = plaintext.Text
If pt.Length Mod 2 <> 0 Then
pt = pt & "e"
End If
pt = UCase(pt)
pt.Replace("J", "I")
Dim Value As String
Dim NewValue As String
key.Replace("J", "I")
Value = key & "ABCDEFGHIKLMNOPQRSTUVWXYZ"
NewValue = ""
Value = UCase(Value)
NewValue = Value(0)
For i As Integer = 1 To Value.Length - 1
If Not (InStr(1, NewValue, Value(i)) > 0) Then
NewValue = NewValue & Value(i)
End If
Next
Dim p As Integer = 0
For n As Integer = 0 To 4
For m As Integer = 0 To 4
lm(n, m) = NewValue(p)
p = p + 1
Next
Next
Dim leave As Boolean = False
For q As Integer = 0 To pt.Length - 1 Step 2
For n1 = 0 To 4
For m1 = 0 To 4
If lm(n1, m1).Equals(pt(q)) Then
leave = True
Exit For
End If
Next
If leave Then
Exit For
End If
Next
leave = False
For n2 = 0 To 4
For m2 = 0 To 4
If lm(n2, m2).Equals(pt(q + 1)) Then
leave = True
Exit For
End If
Next
If leave Then
Exit For
End If
Next
If n1 = n2 Then
If m1 >= 4 Then
m3 = 0
Else
m3 = m1 + 1
End If
If m2 >= 4 Then
m4 = 0
Else
m4 = m2 + 1
End If
ElseIf m1 = m2 Then
If n1 >= 4 Then
n3 = 0
Else
n3 = n1 + 1
End If
If n2 >= 4 Then
n4 = 0
Else
n4 = n2 + 1
End If
Else
n3 = n1
m3 = m2
n4 = n2
m4 = m1
End If
ct = ct & lm(n3, m3) & lm(n4, m4)
Next
ciphertext.Text = ct
ct = ""
End Sub
End Class
it gives error in this line ct = ct & lm(n3, m3) & lm(n4, m4)array out of range
I cuoldn't find why can someone help me ?
Ah, spotted : )
Dim leave As Boolean = False
For q As Integer = 0 To pt.Length - 1 Step 2
For n1 = 0 To 4
You set it to false before the first iteration and inside the loop just before the (q+1)
leave = False
For n2 = 0 To 4
You need to reset leave = False every time you loop:
Dim leave As Boolean
For q As Integer = 0 To pt.Length - 1 Step 2
leave = False ' This was missing
For n1 = 0 To 4
For a shorter code, try:
(a,b,f,g,c)="".join(input("CODE: ").split()),input("Polybius S: "),"","",1
for(i)in(a):
if(c%2)==0:
g+=i
else:
f+=i
c+=1
for(j)in(range(0,len(f))):
if(b.find(f[j])%5)!=(b.find(g[j])%5)and(int(((b.find(f[j]))-(b.find(f[j])%5))/5))!=(int(((b.find(g[j]))-(b.find(g[j])%5))/5)):
print(b[((int(((b.find(f[j]))-(b.find(f[j])%5))/5))*5)+(b.find(g[j])%5)],end="")
print(b[((int(((b.find(g[j]))-(b.find(g[j])%5))/5))*5)+(b.find(f[j])%5)],end="")
elif(b.find(f[j])%5)==(b.find(g[j])%5)and(int(((b.find(f[j]))-(b.find(f[j])%5))/5))!=(int(((b.find(g[j]))-(b.find(g[j])%5))/5)):
print(b[((((int(((b.find(f[j]))-(b.find(f[j])%5))/5))-1)%5)*5)+b.find(f[j])%5],end="")
print(b[((((int(((b.find(g[j]))-(b.find(g[j])%5))/5))-1)%5)*5)+b.find(g[j])%5],end="")
elif(b.find(f[j])%5)!=(b.find(g[j])%5)and(int(((b.find(f[j]))-(b.find(f[j])%5))/5))==(int(((b.find(g[j]))-(b.find(g[j])%5))/5)):
print(b[((int(((b.find(f[j]))-(b.find(f[j])%5))/5))*5)+((b.find(f[j])%5)-1)%5],end="")
print(b[((int(((b.find(g[j]))-(b.find(g[j])%5))/5))*5)+((b.find(g[j])%5)-1)%5],end="")
OK maybe not that short. Or simple

InvalidArgument=Value of '2' is not valid for 'index'

Dim group11_0_count = 0
Dim group11_1_count = 0
Dim group11_2_count = 0
Dim m As Integer = 0
Dim n As Integer = 0
Dim increment2 As Integer
For m = 0 To machings2.Items.Count - 1
For n = 0 To 3
If machings2.Items(m).ToString.Chars(n) = "1" Then
increment2 = increment2 + 1
End If
Next
If (increment2 = 0) Then
group11_0_count = group11_0_count + 1
group11_1_0.Items.Add(machings2.Items(m))
End If
If (increment2 = 1) Then
group11_1_count = group1_1_count + 1
group11_1_1.Items.Add(machings2.Items(m))
End If
If (increment2 = 2) Then
group11_2_count = group1_2_count + 1
group11_1_2.Items.Add(machings2.Items(m))
End If
increment2 = 0
Next
If (group11_0_count > 0 AndAlso group11_1_count > 0) Then
Dim result = ""
Dim index As Integer = 0
Dim gg As Integer = 0
Dim hh As Integer = 0
Dim i As Integer = 0
For hh = 0 To group11_1_count - 1
For gg = 0 To group11_0_count - 1
result = ""
index = 0
For i = 0 To 3
If group11_1_0.Items(gg).ToString.Chars(i) <> group11_1_1.Items(hh).ToString.Chars(i) Then
result &= "-"
index = index + 1
Else
result &= group11_1_0.Items(gg).ToString.Chars(i)
End If
Next
If (index = 1) Then
machings3.Items.Add(result)
End If
Next
Next
End If
I am comparing the items of two combobox items like that
combobox1 items
0000
combobox items
0001
0010
the result will be like that in machings3 combobox
000-
00-0
Here the differnce between two items indicated by - sign
But i am getting InvalidArgument=Value of '2' is not valid for 'index'.
I Can't make sense out of your source and where the IndexOutOfRangeException occurs. But you know that you need 3 Items in a Combobox to access Item with Index 2?! Every collection starts with 0.