PDA

View Full Version : [SOLVED:] Excel VBA to print 3 copies of sheet if it finds something in cell A2.



staicumihai
03-01-2016, 11:24 PM
Hy guys,

I have an Excel file that has 9 sheets (F1, F2, F3, F4, F5, F6, F7, F8, F9)

I have one of the following situations:

1. F1 has data in cell A2 & F2, F3, F4, F5, F6, F7, F8, F9 are empty
- I want to print F1 3 times (3 copies)

2. F1, F2 have data in cell A2 and F3, F4, F5, F6, F7, F8, F9 are empty
- I want to print F1, F2 3 times (3 copies)

3. F1, F2, F3 have data in cell A2 and F4, F5, F6, F7, F8, F9 are empty
- I want to print F1, F2, F3 3 times (3 copies)

4. F1, F2, F3, F4 have data in cell A2 and F5, F6, F7, F8, F9 are empty
- I want to print F1, F2, F3, F4 3 times (3 copies)

5. F1, F2, F3, F4, F5 have data in cell A2 and F6, F7, F8, F9 are empty
- I want to print F1, F2, F3, F4, F5 3 times (3 copies)

6. F1, F2, F3, F4, F5, F6 have data in cell A2 and F7, F8, F9 are empty
- I want to print F1, F2, F3, F4, F5, F6 3 times (3 copies)

7. F1, F2, F3, F4, F5, F6, F7 have data in cell A2 and F8, F9 are empty
- I want to print F1, F2, F3, F4, F5, F6, F7 3 times (3 copies)

8. F1, F2, F3, F4, F5, F6, F7, F8 have data in cell A2 and F9 are empty
- I want to print F1, F2, F3, F4, F5, F6, F7, F8 3 times (3 copies)

9. F1, F2, F3, F4, F5, F6, F7, F8, F9 have data in cell A2
- I want to print F1, F2, F3, F4, F5, F6, F7, F8, F9 3 times (3 copies)

I need to make a VBA code that annalizes which is the correct situation and then prints the data.

Any help would be greatly appreciated.
Thanks a lot guys and have a nice day.

Bob Phillips
03-02-2016, 03:43 AM
Something like


With Worksheets("F1")

If .Range("F1").Value <> "" And _
.Range("A2").Value = "" And .Range("F2").Value = "" And .Range("F3").Value = "" And _
.Range("F4").Value = "" And .Range("F4").Value = "" And .Range("F6").Value ="" And
.Range("F7").Value = "" And .Range("F8").Value = "" And .Range("F9").Value ="" Then

.Printout Copies:=3
End If
End With

'etc.

staicumihai
03-02-2016, 04:30 AM
Thanks a lot man.