jrobin5881
Technical User
Being a relative novice with VBA I cannot figure out whether to Loop or use a select statement. I have in column C a somewhat stable series of elements. Example "C1"
Sale "C2" Del "C3" Tax and then it repeats down the column Sale, Del, Tax etc. The code attached does pretty much what I want (knowing that I have to tweak it a little more). But here's my problem. I only want the data calcualation to ocur in the active cell when "Sale" is seen in the "C" column. The offset works okay but in some of my data sets the row offset needs to change from 4 to 3 because tax dropped out of the series of elements.
My question is should I be using a case select statement to better process my list or am I not using the looping structure correctly? (sample code below, first part formats the sheet as you can see)
ub delColumns()
totDays = InputBox("Enter Total Working Days for Month")
'Range(Selection, Selection.End(xlDown)).Select
Range("D1:H1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlToLeft
Range("E1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlToLeft
Range("F1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlToLeft
Range("F2").Select
Loop2
Range("G2").Select
Loop2
End Sub
Sub Loop2()
' This loop runs as long as there is something in the next column
Do While IsEmpty(ActiveCell.Offset(0, -3)) = False
ActiveCell.Value = ActiveCell.Offset(0, -2).Value * totDays
ActiveCell.Offset(0, -2).Value = ActiveCell.Value
ActiveCell.Offset(4, 0).Select
Loop
End Sub
Sale "C2" Del "C3" Tax and then it repeats down the column Sale, Del, Tax etc. The code attached does pretty much what I want (knowing that I have to tweak it a little more). But here's my problem. I only want the data calcualation to ocur in the active cell when "Sale" is seen in the "C" column. The offset works okay but in some of my data sets the row offset needs to change from 4 to 3 because tax dropped out of the series of elements.
My question is should I be using a case select statement to better process my list or am I not using the looping structure correctly? (sample code below, first part formats the sheet as you can see)
ub delColumns()
totDays = InputBox("Enter Total Working Days for Month")
'Range(Selection, Selection.End(xlDown)).Select
Range("D1:H1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlToLeft
Range("E1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlToLeft
Range("F1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlToLeft
Range("F2").Select
Loop2
Range("G2").Select
Loop2
End Sub
Sub Loop2()
' This loop runs as long as there is something in the next column
Do While IsEmpty(ActiveCell.Offset(0, -3)) = False
ActiveCell.Value = ActiveCell.Offset(0, -2).Value * totDays
ActiveCell.Offset(0, -2).Value = ActiveCell.Value
ActiveCell.Offset(4, 0).Select
Loop
End Sub