ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referring to a column (https://www.excelbanter.com/excel-programming/297782-referring-column.html)

Helen

Referring to a column
 
This may well be a very daft query! I am writing a macro which
analyses data imported to a spreadsheet. The problem is that it is
carrying out analysis on all cells in a column. However, I want to
follow the progression:

1) Is there a data value in Column A, row X?
2) Use that value to calculate the value for Column P, row X
3) Otherwise, move on to row Y.

I've tried If....Then and Do While.... but I don't know how to
specify point 1). How do I persuade the programme to see whether
Column A, row X is empty or not?

Many thanks,
Helen

Pete McCOsh

Referring to a column
 
Helen,

something along these lines should work for the first
twenty rows:

Sub CheckCol()

Dim X as integer

For X = 1 to 20

If Cells(1,x).value< "" Then
.. Do Your Thang Here ..
End If

Next X

End Sub

This will loop 20 times, looking at the the value in
Column A, row x each time - Cells(1,x).value - then
carrying out whatever action you require.

Cheers, Pete.

-----Original Message-----
This may well be a very daft query! I am writing a macro

which
analyses data imported to a spreadsheet. The problem is

that it is
carrying out analysis on all cells in a column. However,

I want to
follow the progression:

1) Is there a data value in Column A, row X?
2) Use that value to calculate the value for Column P,

row X
3) Otherwise, move on to row Y.

I've tried If....Then and Do While.... but I don't know

how to
specify point 1). How do I persuade the programme to see

whether
Column A, row X is empty or not?

Many thanks,
Helen
.


JE McGimpsey

Referring to a column
 
One way:

If IsEmpty(Range("A" & X).Value) Then
'calculate PX
End If

In article ,
(Helen) wrote:

This may well be a very daft query! I am writing a macro which
analyses data imported to a spreadsheet. The problem is that it is
carrying out analysis on all cells in a column. However, I want to
follow the progression:

1) Is there a data value in Column A, row X?
2) Use that value to calculate the value for Column P, row X
3) Otherwise, move on to row Y.

I've tried If....Then and Do While.... but I don't know how to
specify point 1). How do I persuade the programme to see whether
Column A, row X is empty or not?

Many thanks,
Helen


pikus

Referring to a column
 
lastRow = Worksheets(“Sheet1”).UsedRange.Row - 1
Worksheets(“Sheet1”).UsedRange.Rows.Count

For x = 1 To lastRow
If Worksheets(“Sheet1”).Cells(x, 1).Value < “” Then
BLAH BLAH BLAH
End If
Next x

Do you get what I'm doing here? - Piku

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 10:11 AM.

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