Convert Numeric List in Column A to Say Positive, Negative, or Neutral in Column B

scooby33

New Member
Joined
Nov 15, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am very new to VBA and Macros, and I am trying to get the values in column A which are made up of positive and negative numbers to be converted to "positive," "negative," or "neutral." in column B.

Column A Column B
-1 negative
0 neutral
3 -----> positive
-2 negative
4 positive

I currently do not have any code to output neutral, I am just trying to get to get this working before I add that in.

Here is my code below:
Sub SentimentRecode()
Workbooks("Sentiment Recode").Worksheets("Sheet1").Activate

Dim cell As Range
Dim n As Negative
Dim p As Positive

For Each cell In Range("A:A")
If cell.Value < 0 Then
Range("B:B").Value = n
Else
Range("B:B").Value = p
End If
Next cell
End Sub

I have tried about 10 different iterations of code to try and get the output I want, I am currently getting an error that says compile error: user-defined type not defined. Any help would be greatly appreciated!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Here is an alternative solution using Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Conditional Column" = Table.AddColumn(Source, "Custom", each if [Column1] > 0 then "Positive" else if [Column1] = 0 then "Neutral" else if [Column1] < 0 then "Negative" else if [Column1] = null then null else "Neutral"),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Added Conditional Column", {{"Custom", ""}})
in
    #"Replaced Errors"
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,048
Latest member
81jamesacct

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