Results 1 to 19 of 19

Thread: [RESOLVED]VBA-EXCEL How to work with R1C1

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Resolved [RESOLVED]VBA-EXCEL How to work with R1C1

    My function matches the variable in cel R[1]C[-1] with variables in a matrix IsEen and gives back variable 2 when match is true and zero when match is wrong. But it gives me SyntaxError. Can somebody help me fix this function?

    VB Code:
    1. Function LookColumnBackAndRowFuther()
    2.  
    3.   If(16<>Type(MATCH(R[1]C[-1],IsEen,0)),2,0)
    4.  
    5. End Function
    Last edited by Tobian; Feb 21st, 2006 at 06:32 AM.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: VBA-EXCEL How to work with R1C1

    what is the function type?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    Type is an official function in Excel 97. For Example It gives as result 2 if is lyrics, 4 when is value, 16 = Error (like #n/b) or 64 when is matrix. I didn't make this function Type myself.
    When value in r[1]c[-1] is not matching a value in matrix IsEen, the function match() gives back #n/b. Since I only have to know if values are matching and don't have to know which value that might be, I use the syntax "16<>Type()". And yes, I am a true VBA beginner...
    Last edited by Tobian; Feb 16th, 2006 at 08:02 AM.

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA-EXCEL How to work with R1C1

    Tobian
    In your code snippet here you have an IF statement without a THEN statement. - thats what's currently giving you trhe syntax error.

    But if if you resolve that you still have an issue.
    I assume your referring here to the "Type" worksheet function? If so then you have a problem, as this function is not exposed to VBA through the WorksheetFunction object.

    What exactly do you want this function to achieve?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    I think You are right, the Type function is a worksheet-function. I first recorded a makro where I inserted the formula into a cel. Afterwards I made this function of it. Strange that the If-Function is not right.

    OK, What I want the function to do:

    I want the function to look in the cel, one column back and one row up (C[-1]R[1]) and match the value in this cel with a matrix. If there is a match, the function returns a "2", if there is no match the function returns a "0".

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA-EXCEL How to work with R1C1

    When you say a matrix, do you mean a range of cells? If so would you want to pass the range to the function, or will it be the same range evey time you use the function?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    Yes, my matrix is a range of cells I selected in the worksheet and gave it a name. The values in it will not be changed. The values of the matrix must also be available for other functions.

  8. #8
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA-EXCEL How to work with R1C1

    Try this. You will have to change the value of the rngMatrix variable to your named range.


    VB Code:
    1. Function tobian(ByVal LookupValue As Variant) As Long
    2. Dim rngMatrix As Range
    3.  
    4.         Set rngMatrix = ThisWorkbook.Worksheets(1).Range("B4:C11")
    5.        
    6.         If rngMatrix.Find(What:=LookupValue, _
    7.                             LookIn:=xlValues, _
    8.                             LookAt:=xlWhole, _
    9.                             MatchCase:=False) Is Nothing Then
    10.             tobian = 0
    11.         Else
    12.             tobian = 2
    13.         End If
    14.        
    15.         Set rngMatrix = Nothing
    16. End Function
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    I tried the function tobian but it don't work the way I expected.
    I changed the range of rngMatrix to mine. But I have to give the function a value to look for. There is no need for.
    Example: when function Tobian is inserted in cell C3, I want the function to match the value of cell B4 with the rngmatrix and put the result "2" or "0" back in cell C3. When I insert the function in cell Y7, the function has to match the value in cell X8.
    I tried to rebuild the function but the R[-1]C[1] gives SyntaxError.

    VB Code:
    1. Function tobian()
    2. Dim rngMatrix As Range
    3.  
    4.         Set rngMatrix = ThisWorkbook.Worksheets(1).Range("B1:B5")
    5.        
    6.         If rngMatrix.Find(What:=R[-1]C[1], _
    7.                             LookIn:=xlValues, _
    8.                             LookAt:=xlWhole, _
    9.                             MatchCase:=False) Is Nothing Then
    10.             tobian = 0
    11.         Else
    12.             tobian = 2
    13.         End If
    14.        
    15.         Set rngMatrix = Nothing
    16.  
    17. End Function
    Last edited by Tobian; Feb 16th, 2006 at 01:47 PM.

  10. #10
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA-EXCEL How to work with R1C1

    I didn't catch that, sorry. I was assuming you would pass the cell you were checking to the function. Here's a version that doesn't need an input.
    VB Code:
    1. Function tobian() As Long
    2. Dim LookupValue As Variant
    3. Dim rngMatrix As Range
    4.  
    5.         Application.Volatile
    6.        
    7.         LookupValue = Application.Caller.Offset(1, -1).Value
    8.         Set rngMatrix = ThisWorkbook.Worksheets(1).Range("B4:C11")
    9.        
    10.         If rngMatrix.Find(What:=LookupValue, _
    11.                             LookIn:=xlValues, _
    12.                             LookAt:=xlWhole, _
    13.                             MatchCase:=False) Is Nothing Then
    14.             tobian = 0
    15.         Else
    16.             tobian = 2
    17.         End If
    18.        
    19.         Set rngMatrix = Nothing
    20. End Function
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    I think we are almost there now.
    VBA gives Error 424, Object nessessary for:
    LookupValue = Application.Caller.Offset(1, -1).Value

  12. #12
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA-EXCEL How to work with R1C1

    In debug mode can you type the following into the immediates window and let me knwo the result?

    ?Application.Caller.Address
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    Can't find the immediates window, sorry. I am working with Dutch version and I am vba starter. Can you be more specific?

  14. #14
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA-EXCEL How to work with R1C1

    OK, lets try some other questions.
    What cell have you put the formula in when you get the error?
    What is the range for your matrix?
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    Ok, I used range B1:B4. In cell B1 in put the value 1, the formula I put in cell F11. Now I put the value 1 in cell E12. Function should give 2 now but instead gives 0. I get the error when I compile the function, that should be the reason.
    Last edited by Tobian; Feb 16th, 2006 at 03:50 PM.

  16. #16
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: VBA-EXCEL How to work with R1C1

    Hummm, I just did that and its working fine. Can you zip you excel file and upload it as an attachment?

    Here's my sample.
    Attached Files Attached Files
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  17. #17

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    No problem, I'll try. But can it be because of my old 97 version, that it misses certain files? For instance it misses the VEnlLR3.hlp file, this is the vba help file which is not on the 97 installation disc. That's the file the problem solver refers to when I search for Error 424 , but it is not there.
    Attached Files Attached Files
    Last edited by Tobian; Feb 16th, 2006 at 04:16 PM.

  18. #18

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    Quote Originally Posted by DKenny
    In debug mode can you type the following into the immediates window and let me knwo the result?

    ?Application.Caller.Address
    I get Run-time Error 424 Object needed

  19. #19

    Thread Starter
    Member
    Join Date
    Feb 2006
    Location
    Holland
    Posts
    34

    Re: VBA-EXCEL How to work with R1C1

    Oke, I resolved the bug. That means when I use following public function ValueOneBack, I don't get the error 424 anymore. But it doesn't make my function MatchOneBack work the way it has to. But that's another question..

    VB Code:
    1. Public Function ValueOneBack() As Variant
    2.    
    3.     ValueOneBack = ""
    4.    
    5.     Application.Volatile
    6.    
    7.     If TypeName(Application.Caller) = "Range" Then
    8.         If Application.Caller.Row <> 65536 And Application.Caller.Column <> 1 Then
    9.             ValueOneBack = Application.Caller.Offset(1, -1).Value
    10.         End If
    11.     End If
    12.  
    13. End Function
    14.  
    15. Function MatchOneBack() As Integer
    16.     Dim LookupValue As Variant
    17.     Dim rngMatrix As Range
    18.    
    19.     LookupValue = ValueOneBack()
    20.    
    21.     Set rngMatrix = Worksheets(1).Range("B1:B4")
    22.        
    23.     If rngMatrix.Find(What:=LookupValue, _
    24.                         LookIn:=xlValues, _
    25.                         LookAt:=xlWhole, _
    26.                         MatchCase:=False) Is Nothing Then
    27.         MatchOneBack = 0
    28.     Else
    29.         MatchOneBack = 2
    30.     End If
    31.        
    32.     Set rngMatrix = Nothing
    33.    
    34. End Function
    Last edited by Tobian; Feb 20th, 2006 at 11:15 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width