ShowMe function works fine except I need the offset to adjustdepending on column

D

davjoh123

Can someone point me in the right direction for this?

Function Showme(rngSrc As Range) As String
Dim rng As Range, rngMin As Range, dbl As Double, rngLeft As Range
Dim intOffset As Integer

Set rngMin = rngSrc.Cells(1, 1)
dbl = rngMin.Value
For Each rng In rngSrc
If rng.Value < dbl Then
Set rngMin = rng
dbl = rngMin.Value
End If
Next

'Showme = rngMin.Address
Set rngLeft = rngMin.Offset(, -3).Cells(1, 1)
'MsgBox rngMin.Address
'MsgBox rngLeft.Address
'MsgBox rngLeft.Value

Showme = rngLeft.Value



End Function
 
D

davjoh123

Can someone point me in the right direction for this?

Function Showme(rngSrc As Range) As String
   Dim rng As Range, rngMin As Range, dbl As Double, rngLeft As Range
   Dim intOffset As Integer

   Set rngMin = rngSrc.Cells(1, 1)
   dbl = rngMin.Value
   For Each rng In rngSrc
   If rng.Value < dbl Then
      Set rngMin = rng
      dbl = rngMin.Value
   End If
   Next

   'Showme = rngMin.Address
   Set rngLeft = rngMin.Offset(, -3).Cells(1, 1)
   'MsgBox rngMin.Address
   'MsgBox rngLeft.Address
   'MsgBox rngLeft.Value

   Showme = rngLeft.Value

End Function

I solved the problem with the following

intOffset = rngMin.Column
intOffset = "-" & (intOffset - 1)
'Showme = rngMin.Address
Set rngLeft = rngMin.Offset(, intOffset).Cells(1, 1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top