Copy Formula VB

Ody

Board Regular
Joined
Oct 14, 2010
Messages
215
Hello all,

I'm running into a compile error with the following code:

Code:
Sub Macro2()

With Worksheets("B&P Weekly")
 lMaxRows = .Cells(.Rows.Count, "B").End(xlUp).Row
    .Range("B" & lMaxRows + 1).Formula = "='" & Chat Info & "'!D14"
End With



End Sub

Basically, I'm trying to take cell d14 from my Chat Info sheet and place the information in the next available cell in column B on the B&P weekly sheet. There are several other cells I'm transferring, in a similar method, too. Some have formulas. Any way. Appreciate another pair of eyes.

thanks much!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try:
Code:
Sub Macro2()

Dim i as Long
With Worksheets("B&P Weekly")
  i = .Range("B" & Rows.Count).End(xlUp).Row
  .Range("B" & i + 1).Formula = "='Chat Info'!D14"
End With

End Sub
 
Upvote 0
For the situation you've described I'd use the below approach. If you're looking to do this with several cells, I'd suggest a loop.

Code:
Sub Macro2()
Dim lmaxrows As Long


With Worksheets("B&P Weekly")
 
    lmaxrows = .Cells(.Rows.Count, 2).End(xlUp).Offset(1).Row
    .Cells(lmaxrows, 2).Formula = "='Chat Info'!D14"
    
End With


End Sub
 
Upvote 0
JackDanIce, thanks for the help.

njimak, thanks for the suggestion, too.
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,025
Members
448,543
Latest member
MartinLarkin

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