Mismatch error at end of loop - blank cell the problem?

kyleharry

New Member
Joined
Sep 19, 2018
Messages
2
Hi - I am a complete newbie to VBA, but my boss asked me to find a 1-click way for my less tech-savvy colleagues to modify a spreadsheet we receive regularly from a third-party.

In column E is a list of currency values. I need to copy the original values from E to D, then replace the values in E with E multiplied by a decimal number entered into input box by the user.

In a seperate module I make sure to set the cell format in both D and E to "Currency".


Code:
Sub Check()
    Dim rng As Range
    Dim i As Long
    Dim comMultiplyer As Variant
    Dim origCellValue As Variant
    
    'ask for commission multiply variable from user
    comMultiplyer = InputBox("Paste the correct commission multiplyer.")


    'Set the range in column E you want to loop through
    Set rng = Range("E6:E250")
    For Each cell In rng
        'test if cell is empty
        If cell.Value <> "" Then
            'write to adjacent cell
            cell.Offset(0, -1).Value = cell.Value
            cell.Value = cell.Value * comMultiplyer
        End If
    Next
End Sub

The loop seems to complete fine apart from it gets to the cell after that last non-blank cell in E where is throws the mismatch error. I have tried CDec on various parts of this, but I'm not sure what I am doing with that.

Any suggestions?

Kyle
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Kyle

You could check the cell has a numeric value before multiplying.
Code:
If IsNumeric(cell.Value) Then
    cell.Value = cell.Value * comMultiplyer
End If
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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