Macro Recording Issue - Help Appreciated

juuribe

New Member
Joined
Apr 1, 2014
Messages
1
Hi,

I have been trying to record a macro to do the following:

1. Create a new column (always before the last column of the table)
2. Drag the formula from the previous column to the new one.

Example:

Columns: A, B, C, D, E

Need to create a new column always before the last column (E) so now we have E as F and a new blank column in E: A, B, C, D, E(blank), F (with E's data).

Then drag the formulas from column D to the new E (blank).

The problem that I am having is that the Recorded Macro is always creating the new column from the column E. So the first time it works correctly, getting A, B, C, D, E, F. Then, what I get is A, B, C, D, G (new), E, F... then, A, B, C, D, G, H (new), E, F.

Would really appreciate it if anyone could give me some guidance on how to get this working.

Many thanks!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Its basically doing what you told it to, not intelligent enough to know ytou want to do anything different, macros are about reducing repetive tasks. Post your code here in tags, it maybe there is a way to fix it, describe also what you want to happen
 
Upvote 0
The common code is like this:
Code:
Sub doThis()
    Dim lRow&, lCol&
        
    With ActiveSheet
        lRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
        .Columns(lCol).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        .Cells(1, lCol - 1).Resize(lRow, 1).AutoFill Destination:=.Cells(1, lCol - 1).Resize(lRow, 2), Type:=xlFillDefault
    End With
End Sub

In this example we have no table headings and data starts from the first row. Count of rows in table we calculate by "A" column.
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,794
Members
449,468
Latest member
AGreen17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top