VBA: Multiple Cell Selection issues

ryansm05

Board Regular
Joined
Sep 14, 2016
Messages
148
Office Version
  1. 365
Platform
  1. Windows
Hi,

The below code enables me to 'click' for multiple selections as the screenshot highlights.

However, as can be seen in cell K5:
- when selecting '4%' and 'a38%" together - '4%' suddenly become '0.04' and this is causing issues for my lookups.

Does anyone know what is causing this issue and perhaps have a solution to fix it?

Furthermore, if there is a way to achieve 1&2 I would be very much grateful:
1) restrict this code to selecting 2 options only
2) when hitting the DEL button the cell defaults to '[%]'



Dim Oldvalue As String
Dim Newvalue As String


On Error GoTo Exitsub
If Target.Row = 5 Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
Target.Value = Oldvalue & ", " & Newvalue
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub

 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
If the displayed value is 4% then the actual value in the cell is 0.04, if you want the formatted value then use the Text property.
 
Upvote 0
You can see from cell J5 that it is displayed correctly, though.

It's only when the macro selects the two values in the same cell that this formatting issue arises?

My knowledge of macros isn't advanced enough to fix this - do you know a workaround?

Thanks
Ryan
 
Upvote 0
Ryan

In the code you are taking the value in the cell and that value is 0.04.

Like I said, to get the value as it appears use the Text property.

I would post code for that but what you've posted seems incomplete so I'm not sure where/how you would use Text.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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