Results 1 to 9 of 9

Thread: copy properties in Excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    4

    Resolved copy properties in Excel

    Excel makes me crazy I need to make identical copy of cell.
    I need something like
    VB Code:
    1. Worksheets("Sheet1").Cells(1, 1) =  Worksheets("Sheet1").Cells(1, 2)

    but it copyes only value, but I also need fonts, borderds, etc ..

    How can I do it?
    Last edited by vgray; May 1st, 2005 at 03:13 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: copy properties in Excel

    Welcome to the Forums.

    Whenever you need to know how to access most Office VBA properties, you can record a macro doing your task
    and then stop it and check the module code in the vba editor to see how the macro does it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    4

    Re: copy properties in Excel

    Quote Originally Posted by RobDog888
    Welcome to the Forums.

    Whenever you need to know how to access most Office VBA properties, you can record a macro doing your task and then stop it and check the module code in the vba editor to see how the macro does it.
    yeah, really good advice!

    but I think it is not optimal, becouse macro looks like

    VB Code:
    1. Range("D18").Select
    2.     Selection.Copy
    3.     Range("D12").Select
    4.     Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    5.         SkipBlanks:=False, Transpose:=False
    6.     Application.CutCopyMode = False

    Is there another way to do it ?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: copy properties in Excel

    You didnt record yourself adding the formatting to the cell?
    It is only a way to determine what objects/methods/properties are involved. Not necessarily the exact code to use.

    Record your cell formatting and you will get code using something like Cells(1, 1).Font.Interior.ColorIndex and such.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    4

    Re: copy properties in Excel

    Quote Originally Posted by RobDog888
    You didnt record yourself adding the formatting to the cell?
    It is only a way to determine what objects/methods/properties are involved. Not necessarily the exact code to use.

    Record your cell formatting and you will get code using something like Cells(1, 1).Font.Interior.ColorIndex and such.
    aaa, now I understand you, but I thought there is another way than write some thing like

    VB Code:
    1. Cells(1, 1).Font.Interior.ColorIndex = Cells(1, 2).Font.Interior.ColorIndex

    If there is no way, in such case macro will not help me, becouse all properties well described in Excel's help

    Very bad that Excel does not allow something like
    VB Code:
    1. Cells(1, 1).Font = Cells(1, 2).Font

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: copy properties in Excel

    Record a macro of you formatting the first cell with all of the properties that you will need, and you will then have a macro that will format the second cell.
    When you have that, you can use the code to format the cell anytime.

    If the formatting is not the same each time, it will be harder, but as long as you allow for each possibility then you will still be able to use code.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    4

    Re: copy properties in Excel

    thank you guys for help, I've solve my problem

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: copy properties in Excel

    Quote Originally Posted by RobDog888
    ...Record your cell formatting and you will get code using something like Cells(1, 1).Font.Interior.ColorIndex and such.
    dglienna, already suggested in previous post.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    Frenzied Member numtel's Avatar
    Join Date
    Apr 2000
    Location
    CA
    Posts
    1,163

    Re: copy properties in Excel

    VB Code:
    1. Cells(6, 3).Copy Cells(6, 4)
    Just use something like that, that copies C6 to D6 with all the formatting.

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