Advertisement
corpnewt

Excel Bullshit

Feb 9th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. Private Sub ComboBox1_Change()
  2.  
  3. If ComboBox1.Value = "Yes" Then
  4. 'While loop: Iterate from N14-NXX looking for multiple whitespaces
  5. 'in a row in the OXX column then exit loop.
  6.  
  7. 'Initialize search variables
  8. loopDone = False
  9. currentRow = 14
  10. testCol = 15
  11. baseCol = 14
  12. whitespaceCount = 0
  13.  
  14. 'Iterate
  15. Do While loopDone = False
  16. 'Check for whitespace
  17. If Cells(currentRow, testCol).Value <> "" Then
  18. 'No whitespace - reset whitespaceCount
  19. whitespaceCount = 0
  20. 'Set value of current cell to 0.45, and lock
  21. Cells(currentRow, baseCol).Value = 0.45
  22. Cells(currentRow, baseCol).Locked = True
  23. Else
  24. 'Found whitespace - increment whitespaceCount
  25. whitespaceCount = whitespaceCount + 1
  26. 'Check number of whitespaces in a row
  27. If whitespaceCount > 1 Then
  28. 'More than 1 whitespace in a row -
  29. 'Protect the sheet then exit loop
  30. Sheet1.Protect AllowInsertingRows:=True
  31. loopDone = True
  32. End If
  33. End If
  34. 'Increment current row
  35. currentRow = currentRow + 1
  36. Loop
  37. ElseIf ComboBox1.Value = "No" Then
  38. 'While loop: Iterate from N14-NXX looking for multiple whitespaces
  39. 'in a row in the OXX column then exit loop.
  40.  
  41. 'Initialize search variables
  42. loopDone = False
  43. currentRow = 14
  44. testCol = 15
  45. baseCol = 14
  46. whitespaceCount = 0
  47.  
  48. 'Unprotect the sheet prior to the loop
  49. Sheet1.Unprotect
  50.  
  51. 'Iterate
  52. Do While loopDone = False
  53. 'Check for whitespace
  54. If Cells(currentRow, testCol).Value <> "" Then
  55. 'No whitespace - reset whitespaceCount
  56. whitespaceCount = 0
  57. 'Set value of current cell to 0.35, and unlock
  58. Cells(currentRow, baseCol).Value = 0.35
  59. Cells(currentRow, baseCol).Locked = False
  60. Else
  61. 'Found whitespace - increment whitespaceCount
  62. whitespaceCount = whitespaceCount + 1
  63. 'Check number of whitespaces in a row
  64. If whitespaceCount > 1 Then
  65. 'More than 1 whitespace in a row - exit loop
  66. loopDone = True
  67. End If
  68. End If
  69. 'Increment current row
  70. currentRow = currentRow + 1
  71. Loop
  72. End If
  73.  
  74. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement