+ Reply to Thread
Results 1 to 7 of 7

VBA problem with selection/copy specified range of cells

  1. #1
    Registered User
    Join Date
    01-06-2017
    Location
    Poland
    MS-Off Ver
    Office 2016
    Posts
    4

    VBA problem with selection/copy specified range of cells

    Hi Masters!

    I am beginner at vba coding. I want to ask you for help.


    At the beginning I want to create code which should select range of filled. Columns are constant (it should select from e.g. F column to I column, but number of rows are dependend on number of cells where until it will encounter e.g. "THEEND" string.
    I had contrived about use resize() function, but it hasn't returned expected results.
    Result should be like on image. It should select constant columns (F:I) and so many rows as it will encounter "THEEND".

    Sorry for many mistakes, but I really on begin my adventure with VBA.

    Attachment 495978
    My code:
    code.JPG
    (Sorry for adding code in image, but security of forum block me because it claims that it should be sql injection, when i put code in brackets [ code ]
    Last edited by sauron1; 01-07-2017 at 10:28 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA problem with selection/copy specified range of cells

    Hi,

    There's no apparent reason why you can't upload the file. The paperclip attachment icon doesn't work so click the 'Go Advanced' on the right just below your post, then look underneath the post for the 'Manage Attachments' option.

    When you've added the workbook we'll be able to check your code out.
    The macro recorder is great for capturing code initially but it always needs tidying up. For one thing it always captures range addresses for that particular selection which is no good on another occasion. In addition you rarely need .Select and .Activate syntax. You can address objects directly without first selecting them

    Your example code could be probably be simplified to:

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    01-06-2017
    Location
    Poland
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: VBA problem with selection/copy specified range of cells

    Okay, I have uploaded it now.
    Attached Files Attached Files
    Last edited by sauron1; 01-06-2017 at 12:41 PM.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,529

    Re: VBA problem with selection/copy specified range of cells

    I cant't find "THEEND" that is mentioned several times in your first post so maybe you mean this.
    Please Login or Register  to view this content.
    If not, attach a representative file with clearly stating which is the before and what is the after result

  5. #5
    Registered User
    Join Date
    01-06-2017
    Location
    Poland
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: VBA problem with selection/copy specified range of cells

    Hi Jolivanes,
    Yes, you're very very close. Almost you clearify to me how it should look like (it was so simple, but I need learn much more)

    Okay, so let's look on attached file and case (I've modified columns in sheet and macro) - in cell I20 - it's THEEND statement. So macro should stop work, and select/copy only range until "THEEND" - I5:M19
    Do you have idea how it should look like finally? I should use loop to look for "THEEND"? Or maybe its more simple?
    I've attached new template file
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,529

    Re: VBA problem with selection/copy specified range of cells

    Maybe something like this?
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-06-2017
    Location
    Poland
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: VBA problem with selection/copy specified range of cells

    Yes, It works great!
    Thank you jolivanes for help!

+ 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. Copy specific range selection to msword but why it copies columns not in range?
    By adbasanta in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2016, 03:46 AM
  2. Copy paste range of cells based on drop down list selection
    By jrx in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2016, 10:23 AM
  3. Macro to copy and paste a range of cells based on ComboBox selection
    By Paul103 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-07-2015, 03:21 PM
  4. [SOLVED] Copy And Paste Range on diffrenct sheet Selection problem Solved by : sixthsense
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-02-2014, 03:43 AM
  5. range selection problem to copy data from 1 sheet to another
    By apoo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2011, 02:55 AM
  6. Macro Problem, copy range of cells based on criteria
    By Ang12345 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-22-2010, 05:10 PM
  7. Problem with Range,Selection, Copy and Paste
    By ljunggrenus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2007, 07:19 AM

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