Results 1 to 10 of 10
  1. #1
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I have adopted a trick to convert formula's to R1C1 type for using in VBA by setting the formula up in the desired location, and pressing F2 on the cell whilst the macro recorder is on, which provides me with my vba.

    The following 2 formulas report "Unable to record" whilst attempting the above.

    Code:
    =SUMPRODUCT(($C4=$C$4:$C$174)*(F4<F$4:F$174))+1&IF(OR(MOD(SUMPRODUCT(($C4=$C$4:$C$174)*(F4<F$4:F$174))+1,100)={11,12,13}),"th",CHOOSE(MIN(5,RIGHT(SUMPRODUCT(($C4=$C$4:$C$174)*(F4<F$4:F$174))+1)+1),"th","st","nd","rd","th"))
    Code:
    =SUMPRODUCT(($D4=$D$4:$D$174)*(F4<F$4:F$174))+1&IF(OR(MOD(SUMPRODUCT(($D4=$D$4:$D$174)*(F4<F$4:F$174))+1,100)={11,12,13}),"th",CHOOSE(MIN(5,RIGHT(SUMPRODUCT(($D4=$D$4:$D$174)*(F4<F$4:F$174))+1)+1),"th","st","nd","rd","th"))
    Firstly, why is the recorder unable to record this?, and second, please would a kind lounger assist me with the conversion.

    Thanks

    Update:

    I no longer need the conversion, but I am still curious as to why the recorder will not record the action?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The formulas are too long for the macro recorder.

  3. #3

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can also go to the VBE and hit control+g to get into the immediate pane and type ?Activecell.FormulaR1C1 and hit enter.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    You could use this sub to copy the active cell's formula to the clipboard in R1C1 format:
    Code:
    Public Sub CopyCellContents_Sub()
       Dim objData As Object
       Set objData = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    
       'Same as f2+copy contents.
       
       With objData
    	  .SetText Replace(ActiveCell.FormulaR1C1, """", """""")
    	  .PutInClipboard
       End With
    
    End Sub
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='rory' post='799925' date='26-Oct-2009 05:15']
    Code:
    	  Set objData = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    [/quote]

    Hi Rory
    I am confused. Can you explain {1C3B4210-F441-11CE-B9EA-00AA006B1A69} for me?
    Regards
    Don

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    It's the GUID for the MSForms.DataObject. That is the only way I know of to late bind one - you could also simply set a reference to the Forms object library and then use:
    Code:
    Set obJData = New MSForms.DataObject
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    {1C3B4210-F441-11CE-B9EA-00AA006B1A69} is the GUID (unique ID) of the Microsoft Forms DataObject (you can find it in the registry, using RegEdit)
    Rory's code is a way to create an instance of DataObject without having to set a reference to the MS Forms 2.n Object Library.

  9. #9
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post
    [quote name='rory' post='799969' date='26-Oct-2009 12:08']It's the GUID for the MSForms.DataObject. That is the only way I know of to late bind one - you could also simply set a reference to the Forms object library and then use:
    Code:
    Set obJData = New MSForms.DataObject
    [/quote]

    Thank you Rory and Hans.
    Regards
    Don

  10. #10
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks all, a useful topic to come back to next time I am in the same position.

Posting Permissions

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