Macros in Excel 2010

Alabama Man

New Member
Joined
Jan 5, 2010
Messages
9
How can I record following functions in Macro:
(1) Insert a column
(2) Use 'IF' function

The only macros I could record and use later were simple addition and subtarction.
 

Some videos you may like

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,419
Office Version
  1. 2013
Platform
  1. Windows
You can record the insert part by clicking Developer on the ribbon, then click record macro, select the column where you want to insert by clicking on the column designation letter (i.e. A, B, C, etc.), then right click and select 'Insert' from the pop up menu. The insertion is now recorded.
The If statement you would need to write in at the point in the macro where it is logical to do so. Simple If statements like"
Code:
With ActiveSheet 'Use Sheets("Sheetname"<SHEET.NAME>) format where possible
 If .Range("A2") <> .Range("B2") Then
  MsgBox "Not Equal"
 Else
  MsgBox "Equal"
 End If
End With
Can be inserted anywhere in the code.
 
Last edited:

Alabama Man

New Member
Joined
Jan 5, 2010
Messages
9
You can record the insert part by clicking Developer on the ribbon, then click record macro, select the column where you want to insert by clicking on the column designation letter (i.e. A, B, C, etc.), then right click and select 'Insert' from the pop up menu. The insertion is now recorded.
The If statement you would need to write in at the point in the macro where it is logical to do so. Simple If statements like"
Code:
With ActiveSheet 'Use Sheets("Sheetname"<SHEET.NAME>) format where possible
 If .Range("A2") <> .Range("B2") Then
  MsgBox "Not Equal"
 Else
  MsgBox "Equal"
 End If
End With
Can be inserted anywhere in the code.

Thre is no easier method. So if I understand correctly, Macros do not record the functions directly, you have to copy the programmed coding.
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,770
Office Version
  1. 2010
Platform
  1. Windows
The recorder can do no more than record what you do in the user interface.
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,419
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

Thre is no easier method. So if I understand correctly, Macros do not record the functions directly, you have to copy the programmed coding.

I don't think I implied that. There are certain things the recorder cannot record because that particular portion of code is dependent on human rekoning and the recorder facility was not designed to handle that. But, as shg says, it can do more than what you do in the user interface. There are turtorials on using the recorder if you browse the web, you can probably find a free one that will help you out.
 

Alabama Man

New Member
Joined
Jan 5, 2010
Messages
9
I don't think I implied that. There are certain things the recorder cannot record because that particular portion of code is dependent on human rekoning and the recorder facility was not designed to handle that. But, as shg says, it can do more than what you do in the user interface. There are turtorials on using the recorder if you browse the web, you can probably find a free one that will help you out.

Thanks,
 

gardnertoo

Well-known Member
Joined
Jul 24, 2007
Messages
938
When you say you want to record "use the IF function", are you wanting to record what it looks like to use a cell formula containing an IF statement? You can do that by typing such a formula in a cell during the recording. You will end up with a line of code that looks something like this:
Code:
ActiveCell.FormulaR1C1 = "=IF(RAND()>0.5,""Big"",""Small"")"
 

Watch MrExcel Video

Forum statistics

Threads
1,108,708
Messages
5,524,431
Members
409,577
Latest member
Dwg

This Week's Hot Topics

Top