SHARE
TWEET

Untitled

a guest Aug 12th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub LoopThroughColumn()
  2. 'Loop through all of the cells in one column of a small table and add the RowNumber _
  3. to the Sheep value and put the result in the cell to the right
  4. Application.ScreenUpdating = False
  5.  
  6. Dim Counter As Integer
  7. Dim FinalRow As Integer
  8. Dim Header As Range
  9. Dim NewId As Variant
  10.  
  11. Excel.Application.Workbooks("ExcelDemo.xlsm").Worksheets("SleepStudy").Activate
  12.  
  13. Set Header = ActiveSheet.Range("B1")
  14.  
  15. FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
  16.     For Counter = 0 To FinalRow - 2       
  17.     Set NewId = Header.Offset(Counter + 1, 1)
  18.         With NewId           
  19.             .Value = Header.Offset(Counter + 1).Value + Counter + 1 _
  20.                 & "G" & WorksheetFunction.RandBetween(100, 999)           
  21.             .Font.ColorIndex = 25       
  22.         End With
  23.     Next Counter
  24. End Sub
RAW Paste Data
Top