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.
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,912
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,113,810
Messages
5,544,425
Members
410,610
Latest member
renatha prado
Top