+ Reply to Thread
Results 1 to 6 of 6

Four very super basic macros needed

  1. #1
    Registered User
    Join Date
    01-04-2018
    Location
    York, England
    MS-Off Ver
    MS office 2013 & 2010
    Posts
    3

    Four very super basic macros needed

    I've started using excel macros for my work and noticed 4 repetitive tasks which could be simplified with a macro. Do you have a macro formula I can copy and try and out or do you know where I can find them.

    1. Swapping two adjacent cells: e.g. swapping cell B3 with B4

    2. copying the contents of a cell to another column based on color. e.g. if I highlighted cells B3 and B4 in green and left cell B5 and B6 un-colored, then a macro for copying B3 & B4 under column D, without me having to copy and paste manually.

    3. Inserting an often used inspirational piece of text/quote into a cell without having to find the cell containing that quote and copying it. e.g. cell D7 contains quote but I am down working in cell D1007. I want to insert the quote in cell D7 into D1007.

    4. quickly inserting cells containing dates and times; such that I have a template for the year. Best explained by looking at attached workbook. Desired result is on sheet 2 of the workbook.workbook example.xlsx
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Jknight212; 01-04-2018 at 07:03 AM. Reason: attaching workbook with desired results on sheet 2

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,785

    Re: Four very super basic macros needed

    Welcome to the forum!

    Will you please attach a sample Excel workbook? We are not able to work with or manipulate a picture of one and nobody wants to have to recreate your data from scratch.

    1. Make sure that your sample data are REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired results are also shown (mock up the results manually).

    3. Make sure that all confidential data is removed or replaced with dummy data first (e.g. names, addresses, E-mails, etc.).

    4. Try to avoid using merged cells as they cause lots of problems.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

    Please pay particular attention to point 2 (above): without an idea of your intended outcomes, it is often very difficult to offer appropriate advice.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Four very super basic macros needed

    maybe these are close to what you want.

    Please Login or Register  to view this content.
    And for the 4th one isn't this just changing your template to use formula (eg each time is 30 min greater than the one to its left and each date is 1 more than the one above it unless its a header row.) Then pasting it wherever you want?
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  4. #4
    Registered User
    Join Date
    01-04-2018
    Location
    York, England
    MS-Off Ver
    MS office 2013 & 2010
    Posts
    3

    Re: Four very super basic macros needed

    Thanks for this simple and easy to follow advice.

    Will have a go at using these.

    If I get any problems will reply or PM you.

    Cheers

  5. #5
    Registered User
    Join Date
    01-04-2018
    Location
    York, England
    MS-Off Ver
    MS office 2013 & 2010
    Posts
    3

    Re: Four very super basic macros needed

    Unfortunately first formula didn't work, it only swaps the content but not the original cell with its color formatting.
    Tried making my own two formulas (below) to move the content as well as the formatting but they too didn't work.

    Sub swap 1()
    ‘My edit
    a = ActiveCell.
    b = ActiveCell.Offset(0, 1).
    ActiveCell. = b
    ActiveCell.Offset(0, 1). = a
    End Sub

    Sub swap()
    ‘My edit 2
    a = ActiveCell.Value.Interior.ColorIndex
    b = ActiveCell.Offset(0, 1).Value.Interior.ColorIndex
    ActiveCell.Value.Interior.ColorIndex = b
    ActiveCell.Offset(0, 1).Value.Interior.ColorIndex = a
    End Sub



    Didn’t work. Perhaps I misunderstand what selecting the data means. I just selected the cell itself then run the macro
    Sub move()
    ' this assumes you select the data first
    For Each cell In Selection
    a = cell.Interior.ColorIndex
    If a = 12 Then
    cell.Offset(0, 2).Value = cell.Value
    Else: End If
    Next cell
    End Sub


    This one you gave me worked perfectly

    Sub addquote()
    'this assumes the quote is in the selected cell
    a = ActiveCell.Value
    b = InputBox("enter target", "enter target", "A1")
    Range(b).Value = a
    End Sub

  6. #6
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Four very super basic macros needed

    you don't need the ".value" in the color lines

    Please Login or Register  to view this content.
    the macro assumed you are using that specific green as your colour maybe you mean copy as long as it has any colour?

    Please Login or Register  to view this content.

+ 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. Super lookup formula help needed!
    By yayayken in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-08-2015, 04:03 PM
  2. Basic Charting help needed
    By An album cover in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 10-16-2014, 10:46 AM
  3. Replies: 5
    Last Post: 07-26-2012, 09:38 PM
  4. Basic Macro needed
    By alanbenjy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-02-2010, 07:31 AM
  5. basic formula help needed
    By Malchemist in forum Excel General
    Replies: 2
    Last Post: 05-31-2010, 06:49 AM
  6. Basic IF function help needed
    By EME in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-29-2009, 05:51 AM
  7. [SOLVED] Basic Macros?
    By Beginner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-03-2005, 02:06 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