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.

P1583194
P2516995
P8156986
P7268279
P1619275
P7799059
P3519535
P2128841
P6109724
P0925075
P3602976
P4803144
P1207349
P1048230

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>

Thank you!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,213,534
Messages
6,114,184
Members
448,554
Latest member
Gleisner2

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