ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Comparing shitfs macro. (https://www.excelbanter.com/excel-programming/375082-comparing-shitfs-macro.html)

Co-Op dude

Comparing shitfs macro.
 
I am using Excel to keep track of shifts. I have three ****s and each are at
different times. I need a macro that will look through one column of start
times and determines which shift (A, B, C) to put in another column.

Tom Ogilvy

Comparing shitfs macro.
 
Sub fillInShiftColumn()
Dim cell as Range
for each cell in
Range(cells(2,Activecell.Column),cells(20,ActiveCe ll.Column))
if cell.Value = "A" then
cell.offset(0,1).value = "B"
elseif cell.Value = "B" then
cell.offset(0,1).Value = "C"
elseif cell.Value = "C" then
cell.offset(0,1).ClearContents
elsif cell.Value = "" then
cell.offset(0,1).Value = "A"
end if
Next
End sub

or you said times

Sub fillInShiftColumna()
Dim timeA1 as Date, timeA2 as Date, timeB1 as Date
Dim timeB2 as Date, timeC1 as Date, timeC2 as Date
TimeB1 = TimeValue("8:00:00 AM")
TimeB2 = TimeValue("3:59:59 PM")
TimeA1 = TimeValue("4:00:00 PM")
TimeA2 = TimeValue("11:59:59 PM")
TimeC1 = TimeValue("00:00:00 AM")
TimeC2 = TimeValue("7:59:59 AM")
Dim cell as Range
for each cell in
Range(cells(2,Activecell.Column),cells(20,ActiveCe ll.Column))
if cell.Value = TimeB1 and cell.Value <= TimeB2 then
cell.offset(0,1).value = "B"
elseif cell.Value = TimeC1 and cell.Value <= TimeC2 then
cell.offset(0,1).Value = "C"
elseif cell.Value = TimeA1 and cell.Value M= TimeA2 then
cell.offset(0,1).Value = "A"
end if
Next
End sub

This may help you realize you need to enrich your description.

--
Regards,
Tom Ogilvy


"Co-Op dude" <Co-Op wrote in message
...
I am using Excel to keep track of shifts. I have three ****s and each are
at
different times. I need a macro that will look through one column of
start
times and determines which shift (A, B, C) to put in another column.




Delphi Student

Comparing shitfs macro.
 
I apoligize for not being more thurough.

What I have is three shifts: A = 23:00 - 6 :59; B = 7:00 - 14:59; and C =
15:00 - 22:59.

In one column will be the times and another will be for the shift letter.
What I wanted to do was go through the column with the times listed and
determine which shift it belonged to and then print the shift letter in the
other blank column.

If you need anymore information please ask.



Tom Ogilvy

Comparing shitfs macro.
 
Sub fillInShiftColumn()
Dim cell as Range, tm as Date
Dim v as Variant, v1 as Variant
for each cell in Range(cells(2, _
Activecell.Column),cells(20,ActiveCell.Column))
v = ("6:59","14:59","22:59", "11:49")
v1 = ("A","B","C","A")
for i = lbound(v) to ubound(v)
tm = TimeValue(v(i))
if cell.Value <= v(i) then
cell.offset(0,1) = v1(i)
end if
Next
Next
End sub

--
Regards,
Tom Ogilvy


"Delphi Student" <Delphi wrote in message
...
I apoligize for not being more thurough.

What I have is three shifts: A = 23:00 - 6 :59; B = 7:00 - 14:59; and C =
15:00 - 22:59.

In one column will be the times and another will be for the shift letter.
What I wanted to do was go through the column with the times listed and
determine which shift it belonged to and then print the shift letter in
the
other blank column.

If you need anymore information please ask.






All times are GMT +1. The time now is 10:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com