+ Reply to Thread
Results 1 to 10 of 10

Help creating a Variant in VBA

  1. #1
    Registered User
    Join Date
    02-26-2023
    Location
    Texas
    MS-Off Ver
    2019
    Posts
    4

    Help creating a Variant in VBA

    I need some help in Copying a range of cells from sheet ?Tithes? to the next Empty Row on sheet ?Income?. After reading a lot, I got the paste part to work. Because the monthly entry?s count is dynamic I created a VLookup table and used the MAX function to create a referent cell which equal ?W3:AC18? on sheet ?Tithes? cell ?O9?. Any help would be greatly appreciated.

    Option Explicit
    Dim CopyCell As Variant

    Sub SUBMIT2()

    Dim CopyCell As Variant

    Set CopyCell = Worksheets("Tithes").Range("O9")

    Worksheets("Tithes").Range("CopyCell").Copy
    Worksheets("Income").Range("C2").End(xlDown).Offset(1).PasteSpecial xlValues
    Application.CutCopyMode = False

    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Help creating a Variant in VBA

    Untested but try:

    Please Login or Register  to view this content.


    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Post


    ( removed )
    Last edited by Marc L; 04-30-2023 at 08:24 PM.

  4. #4
    Registered User
    Join Date
    02-26-2023
    Location
    Texas
    MS-Off Ver
    2019
    Posts
    4

    Re: Help creating a Variant in VBA

    Thank for your help!
    It still stop on the below line of code:

    Worksheets("Tithes").Range(CopyCell).Copy

    Below is my manual input of Array of (W3:AC18) in to the code and it works:


    Sub SUBMIT2()

    Dim copySheet As Worksheet
    Dim pasteSheet As Worksheet
    Dim CopyRange As Worksheet

    Set copySheet = Worksheets("Tithes")
    Set pasteSheet = Worksheets("Income")

    copySheet.Range("W3:AC18").Copy
    pasteSheet.Range("C2").End(xlDown).Offset(1).PasteSpecial xlValues
    Application.CutCopyMode = False

    End Sub

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    So removing the useless like this VBA demonstration :

    PHP Code: 
    Sub Demo1()
        [
    Income!C2].End(xlDown)(2).Resize(167) = [Tithes!W3:AC18].Value
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Or this ...


    My previous post beginner level VBA demonstration revamped according to the useless cell O9 :

    PHP Code: 
    Sub Demo1r()
        
    With Sheets("Tithes").Range([Tithes!O9])
            [
    Income!C2].End(xlDown)(2).Resize(.Rows.Count, .Columns.Count) = .Value
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  7. #7
    Registered User
    Join Date
    02-26-2023
    Location
    Texas
    MS-Off Ver
    2019
    Posts
    4

    Re: Try this !

    Thanks Marc, not sure what to with you line of code. I don't know if you know that the Sheet "Tithes" cell "O9" stores an array that's dynamic. Which adjust the array size base on the MAX value of a VLookup table.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Help creating a Variant in VBA


    « Array … dynamic » no much sense under Excel as all is static when running a VBA procedure !

    Anyway if cell O9 contains the text "W3:AC18" then my post #6 revamped demonstration well does the job.
    If not so well elaborate your need and / or attach at least a workbook …
    Last edited by Marc L; 04-30-2023 at 09:31 PM. Reason: typo ...

  9. #9
    Registered User
    Join Date
    02-26-2023
    Location
    Texas
    MS-Off Ver
    2019
    Posts
    4

    Re: Help creating a Variant in VBA

    First let me apologize to everyone, that help me on my issue with my spreadsheet. There was a typo on my initial post. The cell referent on the Sheet “Tithes was Q9 not O9.
    The first responds I got worked perfectly, once I made the correction.
    I had been working on this project for too long.
    Thank you all for your help!!
    Charles

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Help creating a Variant in VBA

    You're welcome.



    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Does Excel VBA suppoprt the use of variant record types (not variant data types)
    By tfurnivall in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-25-2022, 12:10 PM
  2. Use of variant
    By miles44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-31-2020, 09:08 AM
  3. DIM variant
    By miles44 in forum Excel General
    Replies: 2
    Last Post: 02-24-2017, 03:00 PM
  4. [SOLVED] A variable defined as variant or variant array
    By billj in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-14-2016, 05:35 PM
  5. Does setting a variant acting as an array equal to "" accomplish same as "Erase" variant?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2014, 05:59 PM
  6. Creating a variant of the SUMIF function
    By nik2shah in forum Excel General
    Replies: 1
    Last Post: 04-29-2008, 01:07 PM
  7. Variant
    By owl527 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2005, 05:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1