insert formula to cell then copy it all the way down

bgonen

Active Member
Joined
Oct 24, 2009
Messages
264
I try to insert a formula "=TEXT(RC[-23],""mm"")&""-""&TEXT(RC[-23],""yy"")"
to cell (col AC row 4) and then copy it all the way down (of Col AC) to the last row that is used

Thanks
bg
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try

Code:
Sub test()
Dim LR As Long
LR = ActiveSheet.UsedRange.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("AC4:AC" & LR).FormulaR1C1 = "=TEXT(RC[-23],""mm"")&""-""&TEXT(RC[-23],""yy"")"
End Sub
 
Upvote 0
Hi Peter
Of course it works; thanks a lot
I will try to struggle myself with the rest of data I try to pull and if I get stuck I will bug again,,,:)
 
Upvote 0
I am trying to insert a command between the Blue shaded and the Green shaded: copy the whole column (AB), pastespecial> value
Sub MatchCopyPaste100()
Dim LR As Long, i As Long, ws As Worksheet
Application.ScreenUpdating = False
With Sheets("JDE") 'select JDE
LR = ActiveSheet.UsedRange.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row 'define LR
Range("AC4:AC" & LR).FormulaR1C1 = "=TEXT(RC[-23],""mm"")&""-""&TEXT(RC[-23],""yy"")" 'Change date format
Range("Ab4:Ab" & LR).FormulaR1C1 = "=IF(RC[-24]>0,RC[-25]&"".""&RC[-24],RC[-25])"
Range("Ad4:Ad" & LR).FormulaR1C1 = "=VLOOKUP(RC[-2],Index!C[-29]:C[-26],3,FALSE)"
End With
End Sub
 
Upvote 0
If I understand correctly try

Code:
Sub MatchCopyPaste100()
Dim LR As Long, i As Long, ws As Worksheet
Application.ScreenUpdating = False
With Sheets("JDE") 'NB. This does not select JDE
    LR = .UsedRange.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row 'define LR
    .Range("AC4:AC" & LR).FormulaR1C1 = "=TEXT(RC[-23],""mm"")&""-""&TEXT(RC[-23],""yy"")" 'Change date format
    With .Range("Ab4:Ab" & LR)
        .FormulaR1C1 = "=IF(RC[-24]>0,RC[-25]&"".""&RC[-24],RC[-25])"
        .Value = .Value
    End With
    .Range("Ad4:Ad" & LR).FormulaR1C1 = "=VLOOKUP(RC[-2],Index!C[-29]:C[-26],3,FALSE)"
End With
End Sub
 
Upvote 0
Peter
Thanks again; it works fine now
I added one more column (col AE ,,shaded blue) but this time I get a compile/reference error
Sub MatchCopyPaste100()
Dim LR As Long, i As Long, ws As Worksheet
Application.ScreenUpdating = False
With Sheets("JDE") 'NB. This does not select JDE
LR = .UsedRange.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row 'define LR
.Range("AC4:AC" & LR).FormulaR1C1 = "=TEXT(RC[-23],""mm"")&""-""&TEXT(RC[-23],""yy"")" 'Change date format Col AC
With .Range("Ab4:Ab" & LR)
.FormulaR1C1 = "=IF(RC[-24]>0,RC[-25]&"".""&RC[-24],RC[-25])" 'Combine two columns (GL acct and Obj acct)
.Value = .Value
End With
.Range("Ad4:Ad" & LR).FormulaR1C1 = "=VLOOKUP(RC[-2],Index!C[-29]:C[-26],3,FALSE)" 'Col AD =type
End With
.Range("Ae4:Ae" & LR).FormulaR1C1 = "=IF(RC[-3]>39999,""P&L"",""Balance-Sheet"")"
End With

End Sub
 
Upvote 0
This compiles

Code:
Sub MatchCopyPaste100()
Dim LR As Long, i As Long, ws As Worksheet
Application.ScreenUpdating = False
With Sheets("JDE") 'NB. This does not select JDE
    LR = .UsedRange.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row 'define LR
    .Range("AC4:AC" & LR).FormulaR1C1 = "=TEXT(RC[-23],""mm"")&""-""&TEXT(RC[-23],""yy"")" 'Change date format Col AC
    With .Range("Ab4:Ab" & LR)
        .FormulaR1C1 = "=IF(RC[-24]>0,RC[-25]&"".""&RC[-24],RC[-25])" 'Combine two columns (GL acct and Obj acct)
        .Value = .Value
    End With
    .Range("Ad4:Ad" & LR).FormulaR1C1 = "=VLOOKUP(RC[-2],Index!C[-29]:C[-26],3,FALSE)" 'Col AD =type
    .Range("Ae4:Ae" & LR).FormulaR1C1 = "=IF(RC[-3]>39999,""P&L"",""Balance-Sheet"")"
End With
End Sub
 
Upvote 0
Hi Peter
Of course it works now,,Thanks again

Hopefully one last question;
I have a pivot table (ws call Pivot) that I am trying to link to the JDE data tab but I need to change the range of the data that the pivot captures (for example right now the last cell is in R7296c31 but each time that I add new data to the JDE sheet the range will increase)
Manual Macro looks like this;

ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
"JDE!R3C1:R7296C31"
ActiveWorkbook.ShowPivotTableFieldList = True
End Sub
 
Upvote 0
Hi.

I suggest that you start a new thread for this. It is a different subject and I'm no expert on PTs.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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