ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Step through a range? (https://www.excelbanter.com/excel-programming/394083-step-through-range.html)

Kent McPherson[_2_]

Step through a range?
 
I have a named range defined in 1 worksheet of my workbook. I want to step
through this range (e.g. 10 rows by 8 columns = 80 cells) one cell at a time
and based on a select case apply formatting to the same cell in another
worksheet in the same workbook. Can someone show me the construct to do
this? I'm no VBA expert as you can tell. Thanks.



Bob Phillips

Step through a range?
 
Dim cell As Range

For Each cell in Range("myRange")
Select Case cell.Value
Case 1: 'do something
'etc.
End Select
Next cell

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Kent McPherson" wrote in message
...
I have a named range defined in 1 worksheet of my workbook. I want to step
through this range (e.g. 10 rows by 8 columns = 80 cells) one cell at a
time and based on a select case apply formatting to the same cell in
another worksheet in the same workbook. Can someone show me the construct
to do this? I'm no VBA expert as you can tell. Thanks.




barnabel

Step through a range?
 
dim currRow as long
dim currCol as integer

for currRow=myRange.Row to myRange.Row+myRange.Rows.Count
for currCol=myRange.Columnto myRange.Column+myRange.Columnes.Count
select case cells(currRow,currCol)
Case 1:

sheets("OtherSheetName").cells(currRow,currCol).nu mberformat="%0.00"
end select
next
next

Peter Richardson

"Kent McPherson" wrote:

I have a named range defined in 1 worksheet of my workbook. I want to step
through this range (e.g. 10 rows by 8 columns = 80 cells) one cell at a time
and based on a select case apply formatting to the same cell in another
worksheet in the same workbook. Can someone show me the construct to do
this? I'm no VBA expert as you can tell. Thanks.





All times are GMT +1. The time now is 10:21 PM.

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