View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Corey Corey is offline
external usenet poster
 
Posts: 172
Default How do i write an offset code ?

Thanks for the reply JMB,
I think you are on the correct reasoning as what i need.
If i use the code for FIND you supplied and modify to something like:

Sub Test()
Dim rngFound As Range

On Error Resume Next
With Worksheets("Sheet4").Range("A:A")
Set rngFound = .Find(what:=Me.combobox1.value, after:=.Range("A1"), _ '
Combobox1 value that is on userform3....
LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, matchbyte:=False)
End With
On Error GoTo 0
' Can i Replace below lines with what is below it.....
<=============================
If Not rngFound Is Nothing Then
Worksheets("Sheet2").Range("A1").Value = _
rngFound.Offset(0, 4).Value ' <========== What would this bit do though
?. I need more than the combobox value.
End If
' Replacement code to bring in other values from Sheet4, from FIND Cell. '
<======================== New lines to relace above section.
Sheet3.range("E2").value = Sheet4.rngFound.Offset(2, -1).value ' Would this
line work OK, if FOUND.Cell was in sheet4.range("A2") and _
the required value was in sheet4.range("C1").value placed in
sheet3.range("E2") ?
Sheet3.range("C3").value = Sheet4.rngFound.Offset(4, 5).value ' Would this
line work OK, if FOUND.Cell was in sheet4.range("A2") and _
the required value was in sheet4.range("E7").value placed in
sheet3.range("C3") ?
Sheet3.range("F5").value = Sheet4.rngFound.Offset(2, 1).value ' Would this
line work OK, if FOUND.Cell was in sheet4.range("A2") and _
the required value was in sheet4.range("C3").value placed in
sheet3.Range("F5") ?
Sheet3.range("H1").value = Sheet4.rngFound.Offset(4, 2).value ' Would this
line work OK, if FOUND.Cell was in sheet4.range("A2") and _
the required value was in sheet4.range("E4").value placed in
sheet3.Range("H1") ?
etc....

End Sub

Will this work OK ?


Corey....

"JMB" wrote in message
...
I think you are looking for the Find method (check VBA help for details)

For example, the macro below will find the cell with the number 45 in
Column
A of Sheet1 and, if a cell w/that value is found, takes the value 4
columns
over (Col E) and puts it in cell A1 of Sheet2. Change the sheet
references
as needed and double check the arguments for the Find method to what you
may
need (you'll certainly need to change "what:=45" to something like "what:=
Me.combobox1.value" (w/o quotes)). I'm assuming this code is intended to
be
put w/the userform that contains your combobox or you'll need some other
means of getting the value of that combobox to use in the search.


Sub Test()
Dim rngFound As Range

On Error Resume Next
With Worksheets("Sheet1").Range("A:A")
Set rngFound = .Find(what:=45, after:=.Range("A1"), _
LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, _
searchdirection:=xlNext, MatchCase:=False, matchbyte:=False)
End With
On Error GoTo 0

If Not rngFound Is Nothing Then
Worksheets("Sheet2").Range("A1").Value = _
rngFound.Offset(0, 4).Value
End If

End Sub



"Corey" wrote:

Thank you for taking time to reply to my post JLGKhiz.

Do you know how i can get the activecell to be the selected value from a
combobox ?
My earlier post 2/1/07 9:02am(about 30 posts ago) explains what i need.

If i can get the selected value from the combobox(Cell in sheet that
contains the value) to be the active cell i am on my way.
At least i think anyhow.

Corey....
"JLGWhiz" wrote in message
...
You can also get some information from "Refering to Cells Relative to
Other
Cells", also in VBA Help.

"Corey" wrote:

I have posted a few times without response, abut am in need of a
method
using the offset(x, x) code.
I have never delt with this type of code before and so cannot workout
how
to start it.
Do i need to set a target cell somehow, to start with so i can offset
cells from it ?

Can anyone assist me in this please?

Corey....