ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Scanning cells to get their value (https://www.excelbanter.com/excel-programming/300053-scanning-cells-get-their-value.html)

Gnappo

Scanning cells to get their value
 
Hi all.

I'm just a beginner in VBA and Excel.

I must scan several contiguous cells, starting from left to right, checking
their value:
if the cell is empty, do nothing and move to check the next one at your
right

if the cell value is 0.25, get column ID (A, B, C...) and store, in another
cell, the value of the corresponding "ID"1 cell.
For example: if I check row 3 and I start checking from cell C3, if the 1st
cell = 0.25 is I3, I must store in my destination cell the value of I0.

Is anybody in there who can help me?

Thank you in advance.

--
Gnappo



Tom Ogilvy

Scanning cells to get their value
 
Set DestRng = Range("M22")
for each cell in Selection
if abs(cell.value = .025) < .00001 then
DestRng = Cell.Address
end if
Next

Your description is not complete - but maybe the above will help.

--
Regards,
Tom Ogilvy


"Gnappo" wrote in message
...
Hi all.

I'm just a beginner in VBA and Excel.

I must scan several contiguous cells, starting from left to right,

checking
their value:
if the cell is empty, do nothing and move to check the next one at your
right

if the cell value is 0.25, get column ID (A, B, C...) and store, in

another
cell, the value of the corresponding "ID"1 cell.
For example: if I check row 3 and I start checking from cell C3, if the

1st
cell = 0.25 is I3, I must store in my destination cell the value of I0.

Is anybody in there who can help me?

Thank you in advance.

--
Gnappo





Gnappo

Scanning cells to get their value
 
Thanks for your help but it does not seem to me to solve the problem but
maybe because I do know the Range object.
Honestly I do not see where you take the corresponding <same column but row
1 cell. It seems to me it gets any cell=0.25 within the range wheather I
must detect the 1st cell from the left.

I try to explain better:

I must scan cells from left to right and, as soon as I get the 1st = 0.25, I
must take the value of the <same column but row 1 cell and put it onto
another empty cell.

Then I must proceed to the (same Row, next+1 Column) next cell and check if
its value is still 0.25. If yes, I must move to the (same Row, next+1
Column) next cell and so on until I do not find the new 1st empty.

When I find the new 1st cell empty, I must take the value of the previous
<same column but row 1 cell and put it onto another empty cell.

By the way, thank you for your effort.

Gnappo


"Tom Ogilvy" wrote in message
...
Set DestRng = Range("M22")
for each cell in Selection
if abs(cell.value = .025) < .00001 then
DestRng = Cell.Address
end if
Next

Your description is not complete - but maybe the above will help.

--
Regards,
Tom Ogilvy


"Gnappo" wrote in message
...
Hi all.

I'm just a beginner in VBA and Excel.

I must scan several contiguous cells, starting from left to right,

checking
their value:
if the cell is empty, do nothing and move to check the next one at your
right

if the cell value is 0.25, get column ID (A, B, C...) and store, in

another
cell, the value of the corresponding "ID"1 cell.
For example: if I check row 3 and I start checking from cell C3, if the

1st
cell = 0.25 is I3, I must store in my destination cell the value of I0.

Is anybody in there who can help me?

Thank you in advance.

--
Gnappo







Tom Ogilvy

Scanning cells to get their value
 
Sub FillCells()
Set rng = Selection
If rng.Rows.Count 1 Then
MsgBox "Select the cells in a single row to be searched"
Exit Sub
End If
If rng.Areas.Count 1 Then
MsgBox "Must be a contiguous set of cells in a single row"
Exit Sub
End If
For Each cell In Selection
Set rng1 = Range(cell.Offset(0, 1), rng(rng.Count))
If IsNumeric(cell.Value) And Not IsEmpty(cell.Value) Then
If Abs(cell.Value - 0.025) < 0.00001 Then
For Each cell2 In rng1
If IsEmpty(cell2) Then
cell2.Value = Cells(1, cell.Column).Value
Exit For
End If
Next
End If
End If
Next

End Sub

Might do what you want.

--
Regards,
Tom Ogilvy


"Gnappo" wrote in message
...
Thanks for your help but it does not seem to me to solve the problem but
maybe because I do know the Range object.
Honestly I do not see where you take the corresponding <same column but

row
1 cell. It seems to me it gets any cell=0.25 within the range wheather I
must detect the 1st cell from the left.

I try to explain better:

I must scan cells from left to right and, as soon as I get the 1st = 0.25,

I
must take the value of the <same column but row 1 cell and put it onto
another empty cell.

Then I must proceed to the (same Row, next+1 Column) next cell and check

if
its value is still 0.25. If yes, I must move to the (same Row, next+1
Column) next cell and so on until I do not find the new 1st empty.

When I find the new 1st cell empty, I must take the value of the previous
<same column but row 1 cell and put it onto another empty cell.

By the way, thank you for your effort.

Gnappo


"Tom Ogilvy" wrote in message
...
Set DestRng = Range("M22")
for each cell in Selection
if abs(cell.value = .025) < .00001 then
DestRng = Cell.Address
end if
Next

Your description is not complete - but maybe the above will help.

--
Regards,
Tom Ogilvy


"Gnappo" wrote in message
...
Hi all.

I'm just a beginner in VBA and Excel.

I must scan several contiguous cells, starting from left to right,

checking
their value:
if the cell is empty, do nothing and move to check the next one at

your
right

if the cell value is 0.25, get column ID (A, B, C...) and store, in

another
cell, the value of the corresponding "ID"1 cell.
For example: if I check row 3 and I start checking from cell C3, if

the
1st
cell = 0.25 is I3, I must store in my destination cell the value of

I0.

Is anybody in there who can help me?

Thank you in advance.

--
Gnappo










All times are GMT +1. The time now is 01:56 PM.

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