jessmoore78
New Member
- Joined
- Sep 13, 2015
- Messages
- 8
Hello everyone,
i am trying to speed up some code I am working on and have a question. The sheet is a log with internal and external worker hours. Unfortunately I can't completely redo the list because it would cause mass hysteria. So I am pretty much just trying to work around it. I format all of the sheets with the same type of format and there are no other problems with the other sheets because I can grab the range from the beginning of the row to the end (last column or curColumn in code) but the workers sheet is different because it has drop down lists and formulas (sums) in certain columns. I just keep resetting the range and adding the format which causes the code to take alot longer. I was wondering if there was maybe a better way of doing this. Here is the code. I have only listed the non standard variable. "i" and "ws" is standard stuff.
I was thinking about running a for each through every cell in the range with a counter that excludes certain cells through select case but I don't think that would be much faster. Would be greatfull for any help anyone could provide. Thanks!
i am trying to speed up some code I am working on and have a question. The sheet is a log with internal and external worker hours. Unfortunately I can't completely redo the list because it would cause mass hysteria. So I am pretty much just trying to work around it. I format all of the sheets with the same type of format and there are no other problems with the other sheets because I can grab the range from the beginning of the row to the end (last column or curColumn in code) but the workers sheet is different because it has drop down lists and formulas (sums) in certain columns. I just keep resetting the range and adding the format which causes the code to take alot longer. I was wondering if there was maybe a better way of doing this. Here is the code. I have only listed the non standard variable. "i" and "ws" is standard stuff.
Code:
Dim dataRange As Range
Dim curColumn As Integer 'the last column to be formatted in the current sheet
'Check the data Range due to inconsistencies in the format so that it doesn't overwrite important cells
Select Case ws.Name 'THIS CODE IS SLOW
Case "Headcount"
Set dataRange = ws.Range(ws.Cells(i, 4), ws.Cells(i, 5))
dataRange.Value = ""
Set dataRange = ws.Range(ws.Cells(i, 7), ws.Cells(i, 9))
dataRange.Value = ""
Set dataRange = ws.Range(ws.Cells(i, 11), ws.Cells(i, 13))
dataRange.Value = ""
Set dataRange = ws.Range(ws.Cells(i, 15), ws.Cells(i, 17))
dataRange.Value = ""
Set dataRange = ws.Range(ws.Cells(i, 19), ws.Cells(i, 21))
dataRange.Value = ""
Set dataRange = ws.Range(ws.Cells(i, 23), ws.Cells(i, curColumn))
dataRange.Value = ""
Case Else
Set dataRange = ws.Range(ws.Cells(i, 4), ws.Cells(i, curColumn))
dataRange.Value = ""
End Select
Else
'Format to Grey
columnRange.Interior.Color = RGB(217, 217, 217)
'Check the data Range due to inconsistencies in the format so that it doesn't overwrite important cells
Select Case ws.Name 'THIS CODE IS SLOW
Case "Headcount"
Set dataRange = ws.Range(ws.Cells(i, 4), ws.Cells(i, 5))
dataRange.Value = "-"
Set dataRange = ws.Range(ws.Cells(i, 7), ws.Cells(i, 9))
dataRange.Value = "-"
Set dataRange = ws.Range(ws.Cells(i, 11), ws.Cells(i, 13))
dataRange.Value = "-"
Set dataRange = ws.Range(ws.Cells(i, 15), ws.Cells(i, 17))
dataRange.Value = "-"
Set dataRange = ws.Range(ws.Cells(i, 19), ws.Cells(i, 21))
dataRange.Value = "-"
Set dataRange = ws.Range(ws.Cells(i, 23), ws.Cells(i, curColumn))
dataRange.Value = "-"
Case Else
Set dataRange = ws.Range(ws.Cells(i, 4), ws.Cells(i, curColumn))
dataRange.Value = "-"
End Select
End If
I was thinking about running a for each through every cell in the range with a counter that excludes certain cells through select case but I don't think that would be much faster. Would be greatfull for any help anyone could provide. Thanks!