configuring macro to run automatically based on dropdown list selection

BrokenIT

New Member
Joined
May 29, 2018
Messages
2
Hi I've created a spreadsheet to record VAT returns for a small computer repair business in Ireland. I like to tweak it to make it run smoother and faster - it has a selection of if statements working well but the macros are proving too difficult to implement.
There are two applicable VAT rates, 23% and 13.5%. Lets say I buy a new screen for a laptop, both VAT rates apply to the transaction. 23% for the screen and 13.5% for the labour for fitting the screen. "Device service with new parts" is an option in a drop down list. If I choose that option, I have to manually add a second row, one row for the labour and one for the parts

[TABLE="width: 610"]
<tbody>[TR]
[TD]No:[/TD]
[TD]Amount[/TD]
[TD]Description[/TD]
[TD]VAT Rate [/TD]
[TD]13.50%[/TD]
[TD]23%[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]30.0[/TD]
[TD]Device Service[/TD]
[TD]low[/TD]
[TD]3.57[/TD]
[TD]0.00[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]30.0[/TD]
[TD]Device Service[/TD]
[TD]low[/TD]
[TD]3.57[/TD]
[TD]0.00[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]50.0[/TD]
[TD]Device Service with new parts[/TD]
[TD]low[/TD]
[TD]5.95[/TD]
[TD]0.00[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]50.0[/TD]
[TD]new parts[/TD]
[TD]High[/TD]
[TD]0.00[/TD]
[TD]9.35[/TD]
[/TR]
</tbody>[/TABLE]

I have this macro that works but I want it to run any time I choose "device service with new parts" from the dropdown list. I would also like it to add the same value to the row in the "No:" column to the new row. In the above example row four should actually be row 3 - there should be two row 3s because both rows apply to the same transaction (the "No:" column refers to a transaction ID in a POS system) I hope Ive explained it well enough...here's the macro

Private Sub Workbook_Open()
'Updateby20150203
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set WorkRng = WorkRng.Columns(1)
xLastRow = WorkRng.Rows.Count
Application.ScreenUpdating = False
For xRowIndex = xLastRow To 1 Step -1
Set Rng = WorkRng.Range("A" & xRowIndex)
If Rng.Value = "Device Service with new parts" Then
Rng.Offset(1, 0).EntireRow.Insert Shift:=xlDown
End If
Next
Application.ScreenUpdating = True
End Sub

Ive have come close to getting it to work automatically but I get syntax errors every time. I don't know much about code, hopefully someone here can help me out.
Regards
John-Paul
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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