I have the following code and VBA is giving me a "Next Without For" Error when I definitely have both. I know that VBA can list errors that are not exactly the same as what it says they are, but I can't find any other closed loops. If someone could check this out, that would be awesome! Thanks:
Option Explicit
Sub HW09()
Dim ng As Integer
Dim v As String
Dim lg As String
Dim ca As Integer
Dim sd As Integer
Dim c As Integer
Dim r As Integer
c = 2
Do
ng = InputBox("Please enter the student's numerical grade.")
If ng < 0 Then
ng = 0
If ng > 100 Then
ng = 100
End If
Cells(c, 2).Value (ng)
c = c + 1
v = InputBox("Would you like to enter another grade? Type 'Y' for yes and 'N' for no.")
If v = "N" Then Exit Do
End If
Loop
Cells(1, 2).Value ("Numerical Grade")
Cells(1, 1).Value ("Letter Grade")
For r = 1 To c
If Cells(r, 2) >= 90 Then
lg = "A"
Cells(r, 1).Value (lg)
If Cells(r, 2) >= 80 Then
lg = "B"
Cells(c, 1).Value (lg)
If Cells(r, 2) >= 70 Then
lg = "C"
Cells(c, 1).Value (lg)
If Cells(r, 2) >= 60 Then
lg = "D"
Cells(c, 1).Value (lg)
Else
lg = "F"
Cells(c, 1).Value (lg)
End If
r = r + 1
Next r
c = c - 1
ca = Application.WorksheetFunction.Average("(1,2):(1,c)")
If ca >= 90 Then
lg = "A"
If ca >= 80 Then
lg = "B"
If ca >= 70 Then
lg = "C"
If ca >= 60 Then
lg = "D"
Else
lg = "F"
End If
MsgBox ("The average letter grade for these " & (c) & " students is " & (lg) & ".")
sd = c * (Application.WorksheetFunction.Sum("(1, 2)(1, c) ^ 2)")-Application.WorksheetFunction.Sum("(1, 2)(1, c)") ^ 2 / (c * (c - 1)))
MsgBox ("The standard deviation for these grades is" & (sd) & ".")
End Sub
Your problem is you are doing If... Then... If... Then... instead of If... Then... ElseIf... Then...
If Cells(r, 2) >= 90 Then
lg = "A"
Cells(r, 1).Value (lg)
ElseIf Cells(r, 2) >= 80 Then
lg = "B"
Cells(c, 1).Value (lg)
ElseIf Cells(r, 2) >= 70 Then
lg = "C"
Cells(c, 1).Value (lg)
ElseIf Cells(r, 2) >= 60 Then
lg = "D"
Cells(c, 1).Value (lg)
Else
lg = "F"
Cells(c, 1).Value (lg)
End If
Every IF statement needs to be terminated with an ENDIF.
Within the FOR/NEXT loop you have 4 IFs, one ELSE and one ENDIF
this needs to be changed to:
IF Condition1 THEN
'code
ELSEIF Condition2 THEN
'code
ELSEIF Condition3 THEN
'code
ELSEIF Condition4 THEN
'code
ELSE 'All other possibilities
'code
ENDIF
I think the nested If statements inside For r = 1 to c... don't close properly? Generally, each If also requires an End If, and you only have one End If statement. This is causing the compiler to reach the Next r statement while it's still "inside" an If block, thus the error raises, and makes sense.
You may look in to using a Select Case switch instead of nesting several If/Then statements. In my experience, they're more easy to interpret when you're debugging. Something like:
For r = 1 To c
Select Case Cells(r,2)
Case >= 90
lg = "A"
Case >= 80
lg = "B"
Case >= 70
lg = "C"
Case >= 60
lg = "D"
Case Else
lg = "F"
End Select
Cells(r,1).Value = lg
r = r + 1 '## You may want to omit this line, see my comments.
Next r
Note: You may want to omit the r = r+1 unless you're intending to skip every other record, the Next statement automatically increments r by a value of 1 unless otherwise specified.
If you do intend to skip every other record, you should do For r = 1 to c Step 2 and likewise omit the r = r+1 .
This error occurs when the condition is not closed.
You must don't forger close if conditions.
for example:
Public Sub start_r()
LastRow = SPT_DB.Range("D" & Rows.count).End(xlUp).Row
Dim i As Long
For i = 3 To 132
State = Cells(1, i)
Dim j As Long
For j = 2 To LastRow
m = SPT_DB.Cells(j, 4).Value
z = SPT_DB.Cells(j, 5).Value
n1 = SPT_DB.Cells(j, 6).Value
fc = SPT_DB.Cells(j, 7).Value
am = SPT_DB.Cells(j, 8).Value
sp = SPT_DB.Cells(j, 10).Value
sr = SPT_DB.Cells(j, 11).Value
liq = SPT_DB.Cells(j, 13).Value
num1 = Val(Left(State, 1))
num2 = Val(Mid(State, 3, 1))
num3 = Val(Mid(State, 5, 1))
num4 = Val(Mid(State, 7, 1))
num5 = Val(Mid(State, 9, 1))
Dim spt_class As spt_class
Set spt_class = New spt_class
Select Case num1
Case Is = 1: Call spt_class.rd_r1
Case Is = 2: Call spt_class.rd_r2
Case Is = 3: Call spt_class.rd_r3
Case Is = 4: Call spt_class.rd_r4
End Select
Select Case num2
Case Is = 1: Call spt_class.msf_r1
Case Is = 2: Call spt_class.msf_r2
Case Is = 3: Call spt_class.msf_r3
Case Is = 4: Call spt_class.msf_r4
Case Is = 5: Call spt_class.msf_r5
Case Is = 6: Call spt_class.msf_r6
End Select
Select Case num3
Case Is = 0:
Case Is = 1: Call spt_class.n1_cs_r1
Case Is = 2: Call spt_class.n1_cs_r2
Case Is = 3: Call spt_class.n1_cs_r3
End Select
Select Case num4
Case Is = 0:
Case Is = 1: Call spt_class.dr_r1
Case Is = 2: Call spt_class.dr_r2
Case Is = 3: Call spt_class.dr_r3
Case Is = 4: Call spt_class.dr_r4
End Select
Select Case num5
Case Is = 1: Call spt_class.crr_r1
Case Is = 2: Call spt_class.crr_r2
Case Is = 3: Call spt_class.crr_r3
Case Is = 4: Call spt_class.crr_r4
Case Is = 5: Call spt_class.crr_r5
Case Is = 6: Call spt_class.crr_r6
Case Is = 7: Call spt_class.crr_r7
Case Is = 8: Call spt_class.crr_r8
Case Is = 9: Call spt_class.crr_r9
End Select
Call spt_class.lvr_r
Next j
If cnt_f_1_all = 0 Then
Cells(4, i) = 0
Else
Cells(4, i) = cnt_f_1_liq * 100 / cnt_f_1_all
Cells(4, i).NumberFormat = "#,##0.00"
End If
If cnt_f_2_all = 0 Then
Cells(5, i) = 0
Else
Cells(5, i) = cnt_f_2_liq * 100 / cnt_f_2_all
Cells(5, i).NumberFormat = "#,##0.00"
End If
If cnt_f_3_all = 0 Then
Cells(6, i) = 0
Else
Cells(6, i) = cnt_f_3_liq * 100 / cnt_f_3_all
Cells(6, i).NumberFormat = "#,##0.00"
End If
If cnt_f_4_all = 0 Then
Cells(7, i) = 0
Else
Cells(7, i) = cnt_f_4_liq * 100 / cnt_f_4_all
Cells(7, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n0_1_all = 0 Then
Cells(14, i) = 0
Else
Cells(14, i) = cnt_f_n0_1_liq * 100 / cnt_f_n0_1_all
Cells(14, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n0_2_all = 0 Then
Cells(15, i) = 0
Else
Cells(15, i) = cnt_f_n0_2_liq * 100 / cnt_f_n0_2_all
Cells(15, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n0_3_all = 0 Then
Cells(16, i) = 0
Else
Cells(16, i) = cnt_f_n0_3_liq * 100 / cnt_f_n0_3_all
Cells(16, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n0_4_all = 0 Then
Cells(17, i) = 0
Else
Cells(17, i) = cnt_f_n0_4_liq * 100 / cnt_f_n0_4_all
Cells(17, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n1_1_all = 0 Then
Cells(24, i) = 0
Else
Cells(24, i) = cnt_f_n1_1_liq * 100 / cnt_f_n1_1_all
Cells(24, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n1_2_all = 0 Then
Cells(25, i) = 0
Else
Cells(25, i) = cnt_f_n1_2_liq * 100 / cnt_f_n1_2_all
Cells(25, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n1_3_all = 0 Then
Cells(26, i) = 0
Else
Cells(26, i) = cnt_f_n1_3_liq * 100 / cnt_f_n1_3_all
Cells(26, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n1_4_all = 0 Then
Cells(27, i) = 0
Else
Cells(27, i) = cnt_f_n1_4_liq * 100 / cnt_f_n1_4_all
Cells(27, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n2_1_all = 0 Then
Cells(34, i) = 0
Else
Cells(34, i) = cnt_f_n2_1_liq * 100 / cnt_f_n2_1_all
Cells(34, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n2_2_all = 0 Then
Cells(35, i) = 0
Else
Cells(35, i) = cnt_f_n2_2_liq * 100 / cnt_f_n2_2_all
Cells(35, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n2_3_all = 0 Then
Cells(36, i) = 0
Else
Cells(36, i) = cnt_f_n2_3_liq * 100 / cnt_f_n2_3_all
Cells(36, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n2_4_all = 0 Then
Cells(37, i) = 0
Else
Cells(37, i) = cnt_f_n2_4_liq * 100 / cnt_f_n2_4_all
Cells(37, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n3_1_all = 0 Then
Cells(44, i) = 0
Else
Cells(44, i) = cnt_f_n3_1_liq * 100 / cnt_f_n3_1_all
Cells(44, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n3_2_all = 0 Then
Cells(45, i) = 0
Else
Cells(45, i) = cnt_f_n3_2_liq * 100 / cnt_f_n3_2_all
Cells(45, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n3_3_all = 0 Then
Cells(46, i) = 0
Else
Cells(46, i) = cnt_f_n3_3_liq * 100 / cnt_f_n3_3_all
Cells(46, i).NumberFormat = "#,##0.00"
End If
If cnt_f_n3_4_all = 0 Then
Cells(47, i) = 0
Else
Cells(47, i) = cnt_f_n3_4_liq * 100 / cnt_f_n3_4_all
Cells(47, i).NumberFormat = "#,##0.00"
End If
Next i
cnt_f_1_liq = 0
cnt_f_2_liq = 0
cnt_f_3_liq = 0
cnt_f_4_liq = 0
cnt_f_1_all = 0
cnt_f_2_all = 0
cnt_f_3_all = 0
cnt_f_4_all = 0
cnt_f_n0_1_liq = 0
cnt_f_n0_2_liq = 0
cnt_f_n0_3_liq = 0
cnt_f_n0_4_liq = 0
cnt_f_n0_1_all = 0
cnt_f_n0_2_all = 0
cnt_f_n0_3_all = 0
cnt_f_n0_4_all = 0
cnt_f_n1_1_liq = 0
cnt_f_n1_2_liq = 0
cnt_f_n1_3_liq = 0
cnt_f_n1_4_liq = 0
cnt_f_n1_1_all = 0
cnt_f_n1_2_all = 0
cnt_f_n1_3_all = 0
cnt_f_n1_4_all = 0
cnt_f_n2_1_liq = 0
cnt_f_n2_2_liq = 0
cnt_f_n2_3_liq = 0
cnt_f_n2_4_liq = 0
cnt_f_n2_1_all = 0
cnt_f_n2_2_all = 0
cnt_f_n2_3_all = 0
cnt_f_n2_4_all = 0
cnt_f_n3_1_liq = 0
cnt_f_n3_2_liq = 0
cnt_f_n3_3_liq = 0
cnt_f_n3_4_liq = 0
cnt_f_n3_1_all = 0
cnt_f_n3_2_all = 0
cnt_f_n3_3_all = 0
cnt_f_n3_4_all = 0
End Sub
Related
there was an error of mismatch type, so the problem on
ElseIf CInt(Cells(2, 3)) <> Year(Sheet9.Cells(a, 51)) And Sheet9.Cells(a, 15) = "APP" Then
I think the problem is not the CInt, CInt function is supplied with a text string. In my opinion the problem code not read <> Year(Sheet9.Cells(a, 51)) because reflect value ""
I don't fill any value on InputBox which mean ""
and my question, how to add statement elseif number <> blank value ("")?
here my full code:
Private Sub btn_check_Click()
Application.ScreenUpdating = False
Dim a, b, x, y, z, c As Long
Dim indicator, puzzlePartner, puzzleRaw As String
a = 5
b = 2
c = 5
Do Until Cells(c, 1) = ""
Sheet9.Cells(c, 3).Select
Sheet9.Cells(c, 56) = Trim(CStr(Left(Sheet9.Cells(c, 3), 15)))
c = c + 1
Loop
a = 5
Do Until Sheet9.Cells(a, 1) = ""
Do Until Sheet4.Cells(b, 104) = ""
If a = 2000 Then
c = 1
End If
If Sheet4.Cells(b, 9) = Sheet9.Cells(a, 9) And Sheet4.Cells(b, 27) = Sheet9.Cells(a, 27) And Sheet4.Cells(b, 26) = Sheet9.Cells(a, 26) And _
Sheet4.Cells(b, 25) = Sheet9.Cells(a, 25) And Sheet4.Cells(b, 24) = Sheet9.Cells(a, 24) And Sheet9.Cells(a, 52) = Sheet4.Cells(b, 104) And _
LCase(Trim(Sheet4.Cells(b, 21))) = LCase(Trim(Sheet9.Cells(a, 21))) Then
Sheet9.Cells(a, 53) = "True"
GoTo 1
ElseIf CInt(Cells(2, 3)) <> Year(Sheet9.Cells(a, 9)) And Sheet9.Cells(a, 15) = "Withdrawn" Then
Sheet9.Cells(a, 53) = "True"
GoTo 1
ElseIf CInt(Cells(2, 3)) <> Year(Sheet9.Cells(a, 9)) And Sheet9.Cells(a, 15) = "DC" Then
Sheet9.Cells(a, 53) = "True"
GoTo 1
ElseIf CInt(Cells(2, 3)) <> Year(Sheet9.Cells(a, 9)) And Sheet9.Cells(a, 15) = "PO" Then
Sheet9.Cells(a, 53) = "True"
GoTo 1
ElseIf Right(Sheet9.Cells(a, 7), 3) = "(S)" Then
Sheet9.Cells(a, 53) = "True"
GoTo 1
ElseIf CInt(Cells(2, 3)) <> Year(Sheet9.Cells(a, 51)) And Sheet9.Cells(a, 15) = "APP" Then
Sheet9.Cells(a, 53) = "True"
GoTo 1
ElseIf CInt(Cells(2, 3)) <> Year(Cells(a, 12)) And Right(Cells(a, 52), 3) = "RNW" Then
Sheet9.Cells(a, 53) = "True"
GoTo 1
End If
End If
2:
b = b + 1
Loop
1:
b = 2
a = a + 1
Loop
End Sub
Anyone have idea why is this happening?
Compiler Error: End With Has No With. I know that this is wrong, and there is something in my code in where I am not calling it correctly that is making it mess up but I cannot find it. I'm just trying to grab information off of my sheet1 so that I can use it later on.
With ThisWorkbook.Sheets("Sheet1")
While (Counter <= 300)
Pcounter = .Cells(ACBoxCounter, 2)
If (Pcounter <> "") Then
ACounter = ACounter + 1
End If
ACBCounter = ACBCounter + 30
Wend
While (OverallACounter < ACounter)
Set objStream = CreateObject("ADODB.Stream")
objStream.Charset = "iso-8859-1"
objStream.Open
ExampleString = .Cells(Row2Counter + 22, 3)
ChooseM = Split(ExampleString, "-")(1)
If (ChooseM = "8")
M = "II"
P = 97
Label = .Cells(Row2Counter, 2)
ElseIf (ChooseM = "13") Then
Model = "A II"
P = 10
Label = "A6_" & .Cells(Row2Counter, 2)
ElseIf (ChooseM = "19") Then
M = "AC1I"
P = 56
Label = "A9_" & .Cells(Row2Counter, 2)
End If
OverallD = 0
Overall= 0
OverallB = 0
ChooseBoxType = Split(ExampleString, "-")(2)
If ((StrComp(ChooseB, "1") = 0) Or (StrComp(ChooseB, "1M") = 0)) Then
BoxInputT= "1 Phase"
ElseIf ((StrComp(ChooseB, "2") = 0) Or (StrComp(ChooseB, "2M") = 0)) Then
BoxInput= "2"
ElseIf ((StrComp(ChooseB ,"3") = 0) Or (StrComp(ChooseBo, "3M") = 0)) Then
BoxInput= "3"
End If
objStream.WriteText (" <" & .Cells(Row2Counter, 2).Text & ">" & vbLf)
Wend
End With
Compiler Error: End With Has No With
I am having an issue with the "Subscript out of Range" error message. I got some help writing a code that loops a long list of stocks. The code basically makes all of the vectors even so i can use it in a panel data setting.
The loop stops after 4 stocks and gives me a "Subscript out of Range" error.
I can run the code over the first 95 "i" i.e. if i transform the first part:
For i = 4 To 95
If Cells(i, 1) <> Cells(i - 1, 1) Then Clean_Stock_2 (i)
Code:
**Sub Outer_Loop()
For i = 4 To Cells(Rows.Count, 1).End(xlUp).Row**
If Cells(i, 1) <> Cells(i - 1, 1) Then Clean_Stock_2 (i)
Next i
End Sub
Sub Clean_Stock_2(ByVal r As Long)
Dim Stock(31, 5)
Dim Quarter(31)
Dim Bo As Boolean
Charge = 0
'Frame
For i = 0 To 31
Stock(i, 0) = Cells(r, 1)
Stock(i, 1) = Cells(r, 2)
Stock(i, 2) = Cells(r, 3)
Stock(i, 5) = "Q" & Format(DateAdd("q", i, #1/1/2011#), "q-YYYY")
Quarter(i) = Stock(i, 5)
Next i
'Data
Do While Cells(r, 1) = Stock(0, 0)
Qu = "Q" & Format(Cells(r, 4), "q-YYYY")
rr = Application.Match(Qu, Quarter, 0)
If Not IsError(rr) Then
Stock(rr, 3) = Cells(r, 4)
Stock(rr, 4) = Cells(r, 5)
If Not Bo Then Charge = Stock(rr, 4): Bo = True
End If
r = r + 1
Loop
'fill
For i = 0 To 31
If Stock(i, 4) = 0 Then
Stock(i, 4) = Charge
Else
Charge = Stock(i, 4)
End If
Next i
'Output
lr = Cells(Rows.Count, "I").End(xlUp).Row + 1
lr = IIf(lr < 3, 3, lr)
Cells(lr, "I").Resize(32, 6) = Stock
End Sub
I need to list the data next to which checkbox is ticked. So I have around 190 check boxes and I need to make a new list in the same sheet having only the checked data. Previously I used Y or N option and this was the code for an idea.
Since I am being forced to add more details I have to write unnecessary words
Sub Button1_Click()
For I = 5 To 45
If (I = 20) Then
I = I + 3
Else
If (I = 28) Then
I = I + 3
End If
End If
If ((Worksheets("tests").Cells(I, 14) <> "Y") And (Worksheets("tests").Cells(I, 14) <> "N")) Then
Worksheets("tests").Cells(250, 2) = Worksheets("tests").Cells(300, 2)
TEMP = I
Range(Cells(233, 1), Cells(233, 1)).Select
GoTo 85
End If
Next I
For I = 83 To 126
Worksheets("tests").Cells(I, 3) = Worksheets("tests").Cells(3, 12)
Worksheets("tests").Cells(I, 2) = Worksheets("tests").Cells(I, 3)
Next I
For I = 133 To 172
Worksheets("tests").Cells(I, 3) = Worksheets("tests").Cells(3, 12)
Worksheets("tests").Cells(I, 2) = Worksheets("tests").Cells(I, 3)
Next I
J = 83
SUM1 = 0
For I = 5 To 19
If (Worksheets("tests").Cells(I, 14) = "Y") Then
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(3, 2)
I = 19
Else
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(3, 12)
SUM1 = SUM1 + 1
End If
Next I
If (SUM1 = 15) Then
GoTo 5
End If
J = J + 2
Sum = 0
For I = 5 To 19
If (Worksheets("tests").Cells(I, 14) = "Y") Then
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(I, 2)
Sum = Sum + 1
Worksheets("tests").Cells(J, 2) = Sum
If (J = 126) Then
J = J + 6
GoTo 30
End If
30
J = J + 1
End If
Next I
Sum = 0
J = J + 1
5
SUM1 = 0
For I = 23 To 27
If (Worksheets("tests").Cells(I, 14) = "Y") Then
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(21, 2)
I = 27
Else
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(3, 12)
SUM1 = SUM1 + 1
End If
Next I
If (SUM1 = 5) Then
GoTo 10
End If
J = J + 2
For I = 23 To 27
If (Worksheets("tests").Cells(I, 14) = "Y") Then
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(I, 2)
Sum = Sum + 1
Worksheets("tests").Cells(J, 2) = Sum
If (J = 126) Then
J = J + 6
GoTo 35
End If
35
J = J + 1
Else
End If
Next I
Sum = 0
J = J + 1
10
SUM1 = 0
For I = 31 To 45
If (Worksheets("tests").Cells(I, 14) = "Y") Then
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(29, 2)
I = 45
Else
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(3, 12)
SUM1 = SUM1 + 1
End If
Next I
J = J + 2
For I = 31 To 45
If (Worksheets("tests").Cells(I, 14) = "Y") Then
Worksheets("tests").Cells(J, 3) = Worksheets("tests").Cells(I, 2)
Sum = Sum + 1
Worksheets("tests").Cells(J, 2) = Sum
If (J = 126) Then
J = J + 6
GoTo 40
End If
40
J = J + 1
Else
End If
Next I
Range(Cells(84, 1), Cells(84, 1)).Select
85
Worksheets("tests").Cells(286, 15).Value = TEMP
250
End Sub
Sub Button63_Click()
TEMP = Worksheets("tests").Cells(286, 15).Value
Range(Cells(TEMP, 14), Cells(TEMP, 14)).Select
End Sub
Sub MASTER()
Range(Cells(1, 1), Cells(1, 1)).Select
End Sub
Sub check()
Range(Cells(5, 14), Cells(5, 14)).Select
End Sub
I have this problem to be sorted out. Namely, I need the code that will place the same values in the range until corresponding cells value increases by one. Once it does the value needs to be incremented by 0.2 and place incremented number until again the corresponding cell value is higher by one
Sub Button4_Click()
range1 = Sheets(3).Range("g2").End(xlDown).Row
range2 = "g2:g" & range1
For i = 2 To range1
If Cells(i, 7).Value <= 360 Then
Cells(i, 8) = 60
range3_n = Cells(i, 8).Row
End If
Next
j = 0.2
k = 1
For i = range3_n To range1
If Cells(i, 7) > 360 And Cells(i, 7) <= (360 + k) And Cells(i, 7) <= (360 +
100) Then
Cells(i, 8) = 60 + (k * j)
k = k + 1
End If
Next
MsgBox ("END")
End Sub
Based on the comments, and keeping the code structure the exact same as it is, an easy solution is adding a new IF Statement after your last one:
IF (Cells(i, 7) - Int(Cells(i, 7)) = 0) Then
The code should look like:
Sub Button4_Click()
range1 = Sheets(1).Range("g2").End(xlDown).Row
range2 = "g2:g" & range1
For i = 2 To range1
If Cells(i, 7).Value <= 360 Then
Cells(i, 8) = 60
range3_n = Cells(i, 8).Row
End If
Next
range3_n = range3_n + 1 'start at cell 361 instead
j = 0.2
k = 1
For i = range3_n To range1
If Cells(i, 7) > 360 And Cells(i, 7) <= (361 + k) And Cells(i, 7) <= (360 + 100) Then
If Int(Cells(i - 1, 7)) - Int(Cells(i, 7)) <> 0 Then
Cells(i, 8) = 60 + (k * j)
k = k + 1
Else
Cells(i, 8) = Cells(i - 1, 8)
End If
End If
Next i
MsgBox ("END")
End Sub
What this does is, it takes the value of the cell, subtracts the integer version of that value (360.1 = 360, 365.4 = 365, etc.) and ensures that equals zero. Any decimal value > .0 will fail, and will not meet the criteria.
Example:
360.0 - 360 = 0 PASS
360.1 - 360 = .1 FAIL
360.4 - 360 = .4 FAIL
360.7 - 360 = .7 FAIL
361.0 - 361 = 0 PASS
Try it out and let me know.