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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,303
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
 

Forum statistics

Threads
1,141,011
Messages
5,703,723
Members
421,311
Latest member
tanujath

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
Top