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

No:AmountDescriptionVAT Rate 13.50%23%
130.0Device Servicelow3.570.00
230.0Device Servicelow3.570.00
350.0Device Service with new partslow5.950.00
450.0new partsHigh0.009.35

<tbody>
</tbody>

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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Anyone any suggestions to make this run automatically? and for a whole column rather than just a cell
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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