Results 1 to 7 of 7

Thread: Converting to VBA code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    74

    Converting to VBA code

    Can someone help me convert this to VBA code?

    If .......(I've got this part)

    Then
    Copy the rows 5 through 50 in the column behind the one you are currently in (offset 0,-1 I believe)
    Now paste special values that colum in some random column (YY?)
    Now copy the same data you just pasted in YY and go back to the original column you were working in and past special "Subtract"

    Thanks!

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Converting to VBA code

    what you would like to do?

    please give more details.

    If ... What?
    CS

  3. #3
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: Converting to VBA code

    dude...better go through an example...
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

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

    Re: Converting to VBA code

    Or just record a macro doing your task. Then stop and view the generated module code.
    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
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Re: Converting to VBA code

    Good Idea Rob....
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

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

    Re: Converting to VBA code

    Yup, recording macros is the #1 way to initially find out how a task is done in most Office apps,where recording macros are supported.

    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

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    74

    Re: Converting to VBA code

    Ok, here is the code I am working on:

    VB Code:
    1. Sub ChangeFormulas()
    2. '
    3. ' Macro1 Macro
    4.  
    5.  
    6. Dim rngCLM As Range
    7. Dim mthval As Object
    8.  
    9.     'mthval is the fiscal month
    10.     Set mthval = ThisWorkbook.Worksheets("External Sales").Range("B2")
    11.    
    12.     'Start with the first column
    13.     Set rngCLM = ThisWorkbook.Worksheets("External Sales").Range("G9")
    14.    
    15.     Do
    16.      
    17.      
    18.         'rngCLM is a number above each of the 12 columns in white font, it it only used as a counter for the macro
    19.         If rngCLM >= mthval Then
    20.         'copy rows 5 through 50 of the preceeding column
    21.         'Paste special values ("hardcode") that data anywhere(just somewhere off to the side)
    22.         'Now copy that hardcoded data you just pasted
    23.         'Now past special values "Subtract" on the original offset (1,0)RngCLM
    24.        
    25.        
    26.         Else
    27.         'Do Nothing
    28.                    
    29.         End If
    30.        
    31.        
    32.         Set rngCLM = rngCLM.Offset(0, 1)
    33.    
    34.         Loop Until rngCLM.Value = ""
    35.    
    36.      
    37. End Sub

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