Macro to Edit a Cell

rhombus4

Active Member
Joined
May 26, 2010
Messages
320
Want to create a macro which will edit cell A1currrenty click a macro button which will select dog, cat, rabbit etc and put in cell A1Once that is selected I want an option where if i need to I can click another button which will add the word food to the cell, for example I select rabbit macro then i select the food button and the cell will say rabbit food
 

Some videos you may like

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

rhombus4

Active Member
Joined
May 26, 2010
Messages
320
At the moment I have a fex boxes, when I click them it will runs a macro which will add some text to cell A1 dog cat rabbit fox etcwhat i want is another box called food so that when i click it after I have clicked one of the animals it will add the word food.Sub Cat'' Cat Macro' Macro recorded 23/07/20010'' Range("A1").Select ActiveCell.FormulaR1C1 = "Cat"End Subwhat i need is when i click the food macro the cell will then become Cat Food
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Like this?

Code:
Sub Food()
    With Range("A1")
        If Len(.Value) = 0 Then
            .Value = "Food"
        Else
            .Value = .Value & " food"
        End If
    End With
End Sub
 

rhombus4

Active Member
Joined
May 26, 2010
Messages
320

ADVERTISEMENT

Like this?

Code:
Sub Food()
    With Range("A1")
        If Len(.Value) = 0 Then
            .Value = "Food"
        Else
            .Value = .Value & " food"
        End If
    End With
End Sub
thanks, I also used ActiveCell.FormulaR1C1 = ActiveCell.Value & " - Food"Only problem I have with both MAcros is is there an option to only select the word once, eg, if i accidently click the food button twice it puts the word food twice
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try:

Code:
Sub Food()
    With ActiveCell
        If InStr(1, .Value, "food", vbTextCompare) = 0 Then
            If Len(.Value) = 0 Then
                .Value = "Food"
            Else
                .Value = .Value & " - Food"
            End If
        End If
    End With
End Sub
 

rhombus4

Active Member
Joined
May 26, 2010
Messages
320

ADVERTISEMENT

Try:

Code:
Sub Food()
    With ActiveCell
        If InStr(1, .Value, "food", vbTextCompare) = 0 Then
            If Len(.Value) = 0 Then
                .Value = "Food"
            Else
                .Value = .Value & " - Food"
            End If
        End If
    End With
End Sub
Is it possible to use the formula below to stop it using the word food twice ActiveCell.FormulaR1C1 = ActiveCell.Value & " - Food"ALso the one you posted doesnt mention cell A1 which seems to throw up an error
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Did you try the code I posted? It only adds the word food if it's not already present. It was you that mentioned ActiveCell so I changed it from Range("A1"). Change it back if you want.
 

rhombus4

Active Member
Joined
May 26, 2010
Messages
320
I currently have:-Sub food() Range("A1").Select WithActiveCell If InStr(1, .Value, " food", vbTextCompare) = 0 Then If Len(.Value) = 0 Then .Value = " food" Else .Value = .Value & " - food" End If End If End With End SubBut it still repeats the word food if I click the button more than once
 

rhombus4

Active Member
Joined
May 26, 2010
Messages
320
Ideally I want the macro below but with the bit about not duplicating the word foodSub food() Range("A1").Select ActiveCell.FormulaR1C1 = ActiveCell.Value & " food" Range("A1").Select End Sub
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,517
Messages
5,511,768
Members
408,864
Latest member
cmajewsk

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top