ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to move to column B1 from column Z1 (https://www.excelbanter.com/excel-programming/387630-how-move-column-b1-column-z1.html)

kiwis

How to move to column B1 from column Z1
 
Hi

my current cell is at column z1, i check for a condition,
if true then i move to column b1 to get the data, if not true, i move
to
next row & then test again.

how do i move to column b1 from column z1?

Do i use the offset function ?

Thank you for any suggestion provided.

kiwis


Norman Jones

How to move to column B1 from column Z1
 
Hi Kiwis,

'---------------
my current cell is at column z1, i check for a condition,
if true then i move to column b1 to get the data, if not true, i move
to
next row & then test again.

how do i move to column b1 from column z1?

Do i use the offset function ?
'---------------

It is usually neither necessary nor desirable to select cells,

An appropriate code might be like:

'============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim Rng2 As Range
Dim rCell As Range
Const vVal = 5

Set WB = Workbooks("MyBook.xls") '<<=== CHANGE
Set SH = WB.Sheets("Sheet1") '<<=== CHANGE
Set Rng = SH.Range("Z1:Z100") '<<=== CHANGE

For Each rCell In Rng.Cells
With rCell
If .Value vVal Then
Set Rng2 = rCell.EntireRow.Cells(2)
MsgBox Rng2.Value
End If
End With
Next rCell
End Sub
'<<============


---
Regards,
Norman




All times are GMT +1. The time now is 03:47 AM.

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