+ Reply to Thread
Results 1 to 9 of 9

VBA to look for blank cells in range and copy with value above

  1. #1
    Valued Forum Contributor jj72uk's Avatar
    Join Date
    03-22-2008
    Location
    Essex, England
    MS-Off Ver
    Work - Office 2000, Home - Office 2007E
    Posts
    360

    VBA to look for blank cells in range and copy with value above

    Im currently using a web query to get some external data for some sales people.

    In this case these sales people usually cover 2 brands.

    The way the SAS code is driven when displayed on our intranet means that the sales agents ID will only display for one of the brands and the correlating second brand will always be below, but the ID will be missing.

    Is there a VBA macro that can be written that will look in a range of cells in a coloum, look to see if its blank and then copy the value from the cell right above it into it?

    I've attached a sheet to show what I mean.
    Attached Files Attached Files
    Last edited by jj72uk; 10-17-2009 at 10:50 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA to look for blank cells in range and copy with value above

    If I've understood, perhaps:

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor jj72uk's Avatar
    Join Date
    03-22-2008
    Location
    Essex, England
    MS-Off Ver
    Work - Office 2000, Home - Office 2007E
    Posts
    360

    Re: VBA to look for blank cells in range and copy with value above

    Donkey,

    You never fail to impress me!

    My VBA is basic. Very basic and though alot of the times I can understand the reasoning why the VBA works, in this case i cannot.

    Mind giving me a quick explination?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA to look for blank cells in range and copy with value above

    The code basically

    a) creates a Range in D based on content of E
    (ie last row can be identified by last non-blank in E, once established offset to left by column to get identical range but in D)

    b) applies SpecialCells logic to the range to identify all Blanks within and subsequently applies formula to the blanks to reference cell above
    (uses R1C1 notation)

    c) removes the formulae by essentially setting the content of each cell to be the present result only

    The On Error statement is required because if no Blanks were found the SpecialCells method would otherwise generate an error.

    The SpecialCells method can be replicated using F5 -> Special -> Blanks -> OK -> = up arrow -> CTRL + ENTER... but depending on the content of the last cell in D you may not get the correct output (ie if last cell in D is blank you won't get a value)

  5. #5
    Valued Forum Contributor jj72uk's Avatar
    Join Date
    03-22-2008
    Location
    Essex, England
    MS-Off Ver
    Work - Office 2000, Home - Office 2007E
    Posts
    360

    Re: VBA to look for blank cells in range and copy with value above

    Very very intresting!!

    Is there a way to encorprecate in to VBA a web query refresh to link to a command button...

    Or.... how about VBA for the query update + the above?

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA to look for blank cells in range and copy with value above

    Sounds like a different question to me... so new thread please.

  7. #7
    Valued Forum Contributor jj72uk's Avatar
    Join Date
    03-22-2008
    Location
    Essex, England
    MS-Off Ver
    Work - Office 2000, Home - Office 2007E
    Posts
    360

    Re: VBA to look for blank cells in range and copy with value above

    Sorry.

    In relation to the orginal question.

    What amendments to the code would be needed if the command button is on a different sheet, but the tables for the VBA code to action is on a sheet called 'data'?

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VBA to look for blank cells in range and copy with value above

    You could try

    Please Login or Register  to view this content.

  9. #9
    Valued Forum Contributor jj72uk's Avatar
    Join Date
    03-22-2008
    Location
    Essex, England
    MS-Off Ver
    Work - Office 2000, Home - Office 2007E
    Posts
    360

    Re: VBA to look for blank cells in range and copy with value above

    Once again, thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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