replace values based on condition

polarnavs

New Member
Joined
Feb 22, 2014
Messages
46
May data looks like

A B C
Time Calls Feed Type
1230 100 Triple

I've written a macro that finds the Triple in column C then copies the entire row and inserts the row 2 times below as listed.
A B C
Time Calls Feed Type
1230 100 Triple
1230 100 Triple
1230 100 Triple

I'd like to write a macro that changes the time in A3 to 1430 and the value of A4 to 1530. Always 120 minutes and 180 minutes more than the first Triple row.

Then I'd like to a second Macro to Replace B2 with 60, B3 and B4 with 20 and 20 (basically splitting the original call volume in a 60:20:20 ratio).
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi Polarnavs,

Try using below code:-

Code:
Sub DILIPandey()
'inserting rows based on a text
Range("c2").Select
While ActiveCell.Value <> ""
    If ActiveCell.Value = "Triple" Then
        t = ActiveCell.Offset(0, -2).Value
        c = ActiveCell.Offset(0, -1).Value
        T0 = t
        T1 = Application.WorksheetFunction.Text(TimeValue(Left(t, 2) & ":" & Right(t, 2)) + TimeValue("2:00:00"), "HHMM")
        T2 = Application.WorksheetFunction.Text(TimeValue(Left(t, 2) & ":" & Right(t, 2)) + TimeValue("3:00:00"), "HHMM")
        c0 = c * 0.6
        c1 = c * 0.2
        c2 = c * 0.2
            For i = 1 To 2
            Selection.Offset(1, 0).EntireRow.Insert
            Next
                ActiveCell.Offset(1, -2).Value = T1
                ActiveCell.Offset(2, -2).Value = T2
                ActiveCell.Offset(0, -1).Value = c0
                ActiveCell.Offset(1, -1).Value = c1
                ActiveCell.Offset(2, -1).Value = c2
                Range(ActiveCell, ActiveCell.Offset(2, 0)).Value = "Triple"
                ActiveCell.Offset(3, 0).Select
    Else
        ActiveCell.Offset(1, 0).Select
    End If
Wend
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,323
Members
449,218
Latest member
Excel Master

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