PDA

View Full Version : Problem when using OFFSET



AlexMason
11-04-2009, 05:06 AM
Im trying to use offset to change the column im in

ie. i find some info using a search in A2 but then want to go 2 columns along (to C2 for instance) to put in a string "checked"

however, just testing this offset thing out give me a complie error: sub or function not defined.

all i was doing is this

CELL = "A2"
CELL = Offset(CELL, 2, 3, 1, 1)

so according to the help file this should make that A2 now C5

am i doing this right? i have a feeling that this is actually a formula that goes into a cell. if so how do i do this move in VBA?

thanks

alex

AlexMason
11-04-2009, 05:15 AM
do i need to use this?

Range("B2").Offset(1,0).Select

or the MSDN version

Worksheets("Sheet1").Activate
ActiveCell.Offset(rowOffset:=3, columnOffset:=3).Activate

markmrw
11-04-2009, 05:25 AM
if you are just trying to select ("B3")
this will work fine
Range("B2").Offset(1,0).select

AlexMason
11-04-2009, 06:32 AM
well what i have is a cell address in a variable named CELL

what i want to do is pick a different cell in the same row, based on the address of CELL

so for instance, CELL is P3 and then i want to put a "CHECKED" string in cell M3

but because CELL is always changing i cant just type "M3" or "P3" because it could be P114 the next time though.


in esscence i want to redefine what CELL is. CELL is P3 then i want to change it to M3 using Offset.

I have this.... to test.....

CELL = "A2"
CELL = Range(CELL).Offset(0,3)


however, that changes the value of CELL from "A2" to "PART"..... whatever that means.

markmrw
11-04-2009, 06:35 AM
could you attach a sample workbook / sheet.

be easier to look at it that way

markmrw
11-04-2009, 06:40 AM
Is this what you are looking for?

Sub test()
Dim ra As Range

Set ra = Range("CELL")
ra.Offset(0, -3).Value = "Checked"
End Sub

AlexMason
11-04-2009, 06:42 AM
ill give that a try and let you know

AlexMason
11-04-2009, 06:46 AM
Cheers Mark this does what i want, works perfectly....thanks!!!!

how do i mark as solved?