Insert Formula into Cell (VBA)

Swissbones

New Member
Joined
Sep 30, 2011
Messages
2
Hi all,


VBA noob here. I am trying to set up a LP problem in excel and I am having trouble setting up a constraint matrix. I need hlep inserting formulas into cells.


Bascially what I am after is:


In cell, Cells(20 + Count2, 4 + Count + p), I want the formula "=range.value*R[20+count2]C[3]"


any ideas?


Thanks...




Code:
Sub InitializeLP()
Dim i As Double, j As Range, Proxies As Double, Row As Integer, RName As String, UColLim As Integer, Count As Integer, NumbSU As Integer, RangeNames() As String, k As Integer, p As Integer, RRange As Range
Dim Count2 As Integer, Count3 As Integer


Proxies = 5
UColLim = 34
NumbSU = 2030 - 2024 + 1
Count = 0
ReDim RangeNames(0 To Proxies - 1)




' Defines Production Name Ranges


For Each j In Range(Cells(3, "B"), Cells(3 + Proxies - 1, "B"))
    Row = j.Row
    RName = j.Value & "_Range"
    ActiveWorkbook.Names.Add Name:=RName, RefersTo:=Range(Cells(3 + Count, 4), Cells(3 + Count, UColLim))
    RangeNames(Count) = RName
    Count = Count + 1
    
Next j




' Generates LP Matrix


For i = 0 To Proxies * NumbSU
    Cells(20 + i, 3) = 1
Next i


Count2 = 0


For i = 0 To Proxies - 1
        RName = RangeNames(i)


    For p = 0 To NumbSU - 1
    Count = 0
    
        For Each RRange In Range(RName)
        
              Cells(20 + Count2, 4 + Count + p) = RRange.Value * Cells(20 + Count2, 3)
              
              Count = Count + 1
              
        Next RRange
        Count2 = Count2 + 1
    Next p
    
Next i
             
              


End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi and welcome to the forum,

I haven't looked through all your code, but perhaps something like this based on what you have:

Code:
Cells(20 + Count2, 4 + Count + p).Formula = _
    "=" & RRange.Value & "*" & Cells(20 + Count2, 3).Address

Note also:
 
Upvote 0
Also, thank you for the link, I did not know that site existed, it will help a lot in my learning process. :)
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,114,002
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