andrewb90
Well-known Member
- Joined
- Dec 16, 2009
- Messages
- 1,077
here is the code I am currently using:
What I am trying to do is in each section add another variable without making the code extremely long. Basically after B2 has a number, I want to check if B11:J11 has the number 1 in it. If it does, I want all the same code that is going to run in sheet 'B1' to also run in sheet G1 or G2, G3,etc. depending on which cell has the number 1 in it (9 possibilities)
I am hoping somebody will have a more efficient code that what I can think of, because I don't what to do 9 If blocks in every section of this code. (the numbers range from 1-50)
I hope this makes some sense...
Thanks,
Andrew
Code:
Sub shift_1()
Sheets("Input").Select
If Range("B2") = "1" Then '**********************1****************
Sheets("B1").Select
Columns("G:G").Select
Selection.Insert Shift:=xlToRight
Range("G1").Select 'TOTAL ACTIONS
ActiveCell.FormulaR1C1 = "1"
End If
If Range("B2") = "2" Then '**********************2****************
Sheets("B1").Select
Columns("G:G").Select
Selection.Insert Shift:=xlToRight
Range("G1").Select 'TOTAL ACTIONS
ActiveCell.FormulaR1C1 = "1"
Range("G3").Select 'add on sales
ActiveCell.FormulaR1C1 = "1"
End If
If Range("B2") = "3" Then '**********************3****************
Sheets("B1").Select
Columns("G:G").Select
Selection.Insert Shift:=xlToRight
Range("G1").Select 'TOTAL ACTIONS
ActiveCell.FormulaR1C1 = "1"
Range("G5").Select 'soda sales
ActiveCell.FormulaR1C1 = "1"
End If
If Range("B2") = "4" Then '**********************4****************
Sheets("B1").Select
Columns("G:G").Select
Selection.Insert Shift:=xlToRight
Sheets("B1").Select
Columns("G:G").Select
Selection.Insert Shift:=xlToRight
Range("G8").Select 'pizza sales
ActiveCell.FormulaR1C1 = "1"
End If
What I am trying to do is in each section add another variable without making the code extremely long. Basically after B2 has a number, I want to check if B11:J11 has the number 1 in it. If it does, I want all the same code that is going to run in sheet 'B1' to also run in sheet G1 or G2, G3,etc. depending on which cell has the number 1 in it (9 possibilities)
I am hoping somebody will have a more efficient code that what I can think of, because I don't what to do 9 If blocks in every section of this code. (the numbers range from 1-50)
I hope this makes some sense...
Thanks,
Andrew