ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need to fill a column if the column next to it is not blank (https://www.excelbanter.com/excel-programming/411018-need-fill-column-if-column-next-not-blank.html)

cqmman

Need to fill a column if the column next to it is not blank
 
Hello,

I don't know much about VBA and Excel 2007 but am working my way
through it slowly.

Basically, I have two columns. A contains several rows of data, and B
is currently empty. Where A is not empty, I want to put a "1" in
column B.

I don't know the best way to do this. I was thinking about selecting
the row and doing some kind of autofill, but that doesn't check the
row next to it. So I suppose I could do something like

Dim i as integer
Set i = 1
Do until i = 1000 'there will never be more than 1000 rows..
If Ai is not blank Then
Bi = 1
End If
Next i


Not really sure how to do that in VBA though!

Spicelon[_2_]

Need to fill a column if the column next to it is not blank
 
Try something like this:

Dim rng as Range, c as Range

Set rng = Range("A1:A10") 'adjust as needed for your own needs
For Each c in rng.Cells
if c.Value = "" then c.Offset(0, 1).Value = 1
Next c

HTH


"cqmman" wrote in message
...
Hello,

I don't know much about VBA and Excel 2007 but am working my way
through it slowly.

Basically, I have two columns. A contains several rows of data, and B
is currently empty. Where A is not empty, I want to put a "1" in
column B.

I don't know the best way to do this. I was thinking about selecting
the row and doing some kind of autofill, but that doesn't check the
row next to it. So I suppose I could do something like

Dim i as integer
Set i = 1
Do until i = 1000 'there will never be more than 1000 rows..
If Ai is not blank Then
Bi = 1
End If
Next i


Not really sure how to do that in VBA though!




cqmman

Need to fill a column if the column next to it is not blank
 
On 15 May, 22:32, "Spicelon" wrote:
Try something like this:

Dim rng as Range, c as Range

Set rng = Range("A1:A10") * * 'adjust as needed for your own needs
For Each c in rng.Cells
* * if c.Value = "" then c.Offset(0, 1).Value = 1
Next c

HTH



Thanks, that is great!


All times are GMT +1. The time now is 06:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com