Can someone tell me the problem with this code please

litestream

Active Member
Joined
Jul 24, 2006
Messages
323
Code:
Private Sub CommandButton1_Click()
    Dim StartValue As Integer
    Dim EndValue As Integer
    Dim Summ As Worksheet
    Dim Lab As Worksheet
    
    Set Summ = Sheets("Summary")
    Set Lab = Sheets("Label")
    
    Dim v As Integer
    
    StartValue = 1
    EndValue = Worksheets("Summary").Range("L19").Value
    For v = StartValue To EndValue
        Lab.Range("F28").Value = v
        Lab.Range("K28").Value = Summ.Range("L19")
        Lab.Range("A1").Value = Summ.Range("D3")
        Lab.Range("A9").Value = Summ.Range("D11")
        Lab.Range("B17").Value = Summ.Range("O13")
        Lab.Range("E17").Value = Summ.Range("O11")
        Lab.Range("A35").Value = Summ.Range("B19")
        Lab.Range("A42").Value = Summ.Range("D19")
        If v = EndValue And Lab.Range("J19") > 0 Or Lab.Range("K19") > 0 Then
        Lab.Range("B17").Value = Summ.Range("J19")
        Lab.Range("I17").Value = Summ.Range("K19")
        Lab.Range("E17").Value = Summ.Range("O11")
        Lab.Range("H17").Value = "+"
        Lab.Range("K17").Value = Summ.Range("K17")
        Lab.Range("K17").Value = "Odds"
        End If
        Lab.PrintOut Copies:=1, Collate:=True
    Next v

End Sub

Code:
        If v = EndValue And Lab.Range("J19") > 0 Or Lab.Range("K19") > 0 Then....

If v = Endvalue AND either J19 or K19 or indeed both J19 and K19 are greater then 0 then it should carry out the rest of the code.

I'm not sure as to the format to use when using IF, OR, AND statements.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Not 100% sure but I think it's just a case of missing parentheses.
Code:
If v = EndValue And (Lab.Range("J19") > 0 Or Lab.Range("K19") > 0) Then
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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