Search and Offset Multiple Strings

peerogel

Board Regular
Joined
Jan 25, 2011
Messages
108
I need help creating a code that searches for multiple "items", grabs the offset and pastes it in another sheet. My final goal is to track leave used. I started with Sunday, Sunday is the only day that uses special WK codes. The rest of the week uses the same code. I will be pasting the rest of the week days in adjacent columns.

What i am trying the code to do, is if it the column has HW codes, add them and put them in the Leave Audit sheet as a WK day. But if there is any type of leave used for that day add all leave instead. I was able to figure out how to add the WK days but once I started trying to figure out how to implement the Leave I got lost. Maybe if there is multiple leave used for the day put "MUL" as the descriptor.

The Hours for Sunday are stored in Sheet "Pay1" ED2:ED30. The codes are adjecsent to the hours in EA2:EB30 (merged). I put the Handler because the the cells have formulas and i kept getting errors on cells with no values (only formula).

Code:
Sub SundayTest()
Dim wks As Worksheet, ws
Set ws = Sheets("Leave Audit")
Set wks = Sheets("Pay1")


On Error GoTo Handler


Dim rng As Range
Dim row As Range
Dim cell As Range
'Leave Audit
Set rng = wks.Range("ED2:ED30")
For Each row In rng.Rows
  For Each cell In row.Cells
    If cell.Value > 0 Then
        
          
       If cell.Offset(0, -3).Value = "61" Then
         ws.Range("C4").Value = "AL"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "62" Then
         ws.Range("C4").Value = "SL"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "63" Then
         ws.Range("C4").Value = "R/AL"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "64" Then
         ws.Range("C4").Value = "CT"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "65" Then
         ws.Range("C4").Value = "ML"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "67" Then
         ws.Range("C4").Value = "COP"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "68" Then
         ws.Range("C4").Value = "EML"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "71" Then
         ws.Range("C4").Value = "LWOP"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "72" Then
         ws.Range("C4").Value = "AWOP"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "73" Then
         ws.Range("C4").Value = "SUS"
         ws.Range("C5").Value = cell.Value
         Else
       If cell.Offset(0, -3).Value = "74" Then
         ws.Range("C4").Value = "FUR"
         ws.Rage("C5").Value = cell.Value
      Else
       If cell.Offset(0, -3).Value = "05" Then
         ws.Range("C4").Value = "WK"
         ws.Range("C5").Value = ws.Range("C5").Value + cell.Value
                End If
        If cell.Offset(0, -3).Value = "04" Then
         ws.Range("C4").Value = "WK"
         ws.Range("C5").Value = ws.Range("C5").Value + cell.Value
        End If
        


            End If
         End If
            End If
                End If
                    End If
                        End If
                            End If
                                End If
                                    End If
                                        End If
                                            End If
                                                End If


    
  Next cell
Next row
Handler:
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top