Boolean value converted to binary

imnie

New Member
Joined
Apr 21, 2002
Messages
22
Good afternoon,

I'm a little stumped about the results I'm getting. I have the following code:

Private Sub cbSave_Click() 'Saving input results to master data sheet
Dim NextInputRow As Range

Set NextInputRow = ActiveWorkbook.Sheets("Sheet2").Range("A65536").End(xlUp).Offset(1, 0)
NextInputRow.Value = Sheets("Sheet1").Range("SurveyID").Value

NextInputRow.Offset(0, 1).Value = Range("Q1_Resp").Value * 1 'Multiply by 1 to force to integer
NextInputRow.Offset(0, 2).Value = Range("Q2_Resp").Value * 1
NextInputRow.Offset(0, 3).Value = Range("Q3_Resp").Value * 1

End Sub

I thought by multipling a True / False value by 1 I would convert a True to 1 and a False to 0. However, instead I get a -1 for the True responses. Does anyone now where the negative is coming from?

Thanks for any help.

Crystal
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I thought by multipling a True / False value by 1 I would convert a True to 1 and a False to 0. However, instead I get a -1 for the True responses. Does anyone now where the negative is coming from?


Hi

In vba True converted to number equals -1. In the worksheet it would be +1.
 
Upvote 0
... and if you want to convert in vba True/False to 1/0 try:

Code:
NextInputRow.Offset(0, 1).Value = IIf(Range("Q1_Resp").Value, 1, 0)
 
Upvote 0

Forum statistics

Threads
1,222,902
Messages
6,168,938
Members
452,227
Latest member
sam1121

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