Copy a formula from the above row VBA

karolina1406

Board Regular
Joined
Apr 18, 2016
Messages
110
Office Version
  1. 365
Platform
  1. Windows
I am using a Userform to populate my Order table. I am using the below code which is fine other than I have a formula in Column G but after populating the table with the Userform info - the formula is not copied. Cas someone help?

Dim oNewRow As ListRow
Dim rng As Range
Set rng = ThisWorkbook.Worksheets("Order_info").Range("NewOrderInfo")
rng.Select
Set oNewRow = Selection.ListObject.ListRows.Add(AlwaysInsert:=True)

With ws
oNewRow.Range.Cells(1, 1).Value = Me.OrderNumber.Value
oNewRow.Range.Cells(1, 2).Value = Me.CustomerName.Value
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
It should work if you change "value" to "formula"
 
Upvote 0
It should work if you change "value" to "formula"
unfortunately not.... Now, my UserForm has 2 TextBoxes: SiteNumber and SiteAddress. Only one of them is compulsory to populate the form. So if the user puts SiteNumber - the formula in excel should pick up the address. But it doesn't as it probably "reads" SiteAddress textbox from the UserForm as blank.

So i need a code for my USerForm something along the lines of:
If SiteNumber textbox populated then find address for this site number from "Sites" tab and populate column "Site Address" in the table in the "order_info" tab.
Otherwise, if SiteNumber textbox is not populated - populate column "Site Address" in the table in the "Order_info" tab with the address from SiteAddress of the UserForm

Hope it makes sense
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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