VBA to assign letter in cell next to a cell with a number

DDePoy

New Member
Joined
Jan 8, 2017
Messages
9
Hello,

I would like to place a letter in all cells in column A when the cell next to it in column B has a number, and for it to stop running when the last cell in column B does not have a value.

[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]P[/TD]
[TD="class: xl63, width: 64, align: right"]1583194[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]2516995[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]8156986[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]7268279[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]1619275[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]7799059[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]3519535[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]2128841[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]6109724[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]0925075[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]3602976[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]4803144[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]1207349[/TD]
[/TR]
[TR]
[TD]P[/TD]
[TD="class: xl63, align: right"]1048230[/TD]
[/TR]
</tbody>[/TABLE]

Thank you!
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Could there be blank cells mixed in with the cells in Column B that have values in them or is the data contiguous?

When Column B cells have a value, will that value always be a number or could some cells have text in them?

Is Column B the only cells that have any values in them or do you have other columns with data as well? If yes, is Column C empty or not?
 
Upvote 0
Which letters do you want to put, always the letter "p"?
 
Upvote 0
Could there be blank cells mixed in with the cells in Column B that have values in them or is the data contiguous?

When Column B cells have a value, will that value always be a number or could some cells have text in them?

Is Column B the only cells that have any values in them or do you have other columns with data as well? If yes, is Column C empty or not?

Thanks for your response. The data is contiguous, I have a macro that eliminates rows with zeros and blanks in Column B. The values in Column B will always be a number, all other Columns are empty. This is a format to import into another program and I believe all other columns must remain empty.

The letter "P" is the only letter that will be used in Column A.
 
Upvote 0
Thanks for your response. The data is contiguous, I have a macro that eliminates rows with zeros and blanks in Column B. The values in Column B will always be a number, all other Columns are empty. This is a format to import into another program and I believe all other columns must remain empty.

The letter "P" is the only letter that will be used in Column A.
As as macro...
Code:
Sub AddPsToColumnAIfNumberInColumnB()
  Columns("B").SpecialCells(xlConstants).Offset(, -1) = "P"
End Sub
But note that this single line of code can be placed at the end of your existing macro that eliminates the zeros and blanks.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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