VBA (probably) to separate data based on occupied cells

Excellingconfusion

New Member
Joined
Apr 18, 2019
Messages
3
Hello,

I am trying to create an Excel file that will scrub the output of a program I use (excel file output) into the format of the input I need for a different program. My issue arises when the output file will put the minutes of an employee into various columns of the same row based on regular, overtime, or doubletime; while the input to the other program needs them to be separate rows. For the output, Pay Type is 1 for regular hours, 2 for overtime, and 3 for doubletime. Paygroup is just a placeholder column. The output format requires that for each different pay type, there need to be a new line. E.g. the input file has employee 415 on cost code 91.105 for 90 minutes regular time and then 180 minutes overtime in that same column. The output will need to have employee 415 listed twice with this cost code to break apart those different pay types and then have the minutes from the appropriate column added. I also need to remove any letters off the end of the cost codes in the output which I was using this function to do. =IF(Input!C4<>"",IF(ISERR(RIGHT(Input!C4,1)*1),LEFT(Input!C4,LEN(Input!C4)-1),Input!C4),"")

Input Format:
DateEmployee #Cost CodeCost Code TypeUOMRegular MinutesOT MinutesDoubletime MinutesBid AreaBid Typical Area
1/18/1937691.108cLF120B1
1/18/1937691.116Acsf36024090B1
1/18/1940691.171BcLF48060B1

<tbody>
</tbody>

Ideal Output:
# EmployeeCost CodePay TypePaygroup (Place Holder)Hours
37691.10812
37691.11616
37691.11624
37691.11631.5
40691.17118
40691.17121

<tbody>
</tbody>


Please Help!!!!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
try this on a copy of you file.

create a worksheet name Results

then run this with your main sheet the active sheet

Code:
Sub Do_it()

With Worksheets("results")

wr = 2

For r = 2 To Cells(Rows.Count, "A").End(xlUp).Row

For c = 6 To 8 'llop thru pay types
If Cells(r, c) <> "" Then
.Cells(wr, "A") = Cells(r, "B") 'ID
.Cells(wr, "B") = Left(Cells(r, "C"), 6) 'Cost Code
.Cells(wr, "C") = c - 5 'pay type
.Cells(wr, "E") = Cells(r, c) / 60 'Hours

wr = wr + 1
End If
Next c

Next r
End With

End Sub

hth,

Ross
 
Upvote 0
I added it and encountered a runtime at line 13 when executed: Type Mismatch

This was this line:

" .Cells(wr, "E") = Cells(r, c) / 60 'Hours "

Any idea?

Thanks for your help Ross!

-Ryan
 
Upvote 0
Scratch that, I forgot to switch to only run this on that workbook, rather than all open workbooks. It worked!!!!

You are a gentleman and a scholar. Very appreciated.
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,611
Members
449,109
Latest member
Sebas8956

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