Skip to content

Instantly share code, notes, and snippets.

@Opiprog
Last active January 1, 2016 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Opiprog/8175195 to your computer and use it in GitHub Desktop.
Save Opiprog/8175195 to your computer and use it in GitHub Desktop.
Excel VB Macro - Updating cycle numbers
Sub UpdateCycleNum()
Dim CellSelect As Long
Dim CycAdd As Long
Dim rng As Range
CellSelect = 1000
CycAdd = 67000
'Set the range in column A you want to loop through
Set rng = Range("A39481:A56510")
For Each cell In rng
'test if cell contains "Begin Cycle" Statement
If cell.Value = "Begin Cycle" Then
'Correct the Number of Cycles
cell.Offset(0, 2) = "=RC[-1]+319067"
'test if cell contains "End Cycle" Statement
ElseIf cell.value = "End Cycle" Then
'Correct the Number of Cycles
cell.Offset(0, 2) = "=RC[-1]+319067"
End If
Next
End Sub
'''''''''' NOTES/CODE ''''''''''''
If
Range("CellSelect").Select
ActiveCell.FormulaR1C1 = "=RC[-1]+CycAdd"
' Range("C3").Select
End Sub
Sub Check()
Dim rng As Range
Dim i As Long
'Set the range in column A you want to loop through
Set rng = Range("A1:A100")
For Each cell In rng
'test if cell is empty
If cell.Value <> "" Then
'write to adjacent cell
cell.Offset(0, 1).Value = "My Text"
End If
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment