Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default writing formulas in VB - referring to the values contained in cell

I'm new to writing code from scratch and I'm struggling with something.

Basically I have a row of numbers and beneath it I need a row which is the %
value that the number above is of the leftmost number. ie:

50 42 8
84 16

The row is a different number on every sheet so I can't use specific cell
references. I've managed to name all the cells that's not the problem, but
I'm unsure of the syntax for the mathmatical formula.

per1 = (p2 / (p1 / 100)) where p2 and p1 are names of cells, and per1 is a
string isn't working.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default writing formulas in VB - referring to the values contained in cell

OK, I've realised that wasn't very clear. I've made some progress actually

-irrelevant code-
Dim per1 As String
per1 = "=sum(" & r3 & ":" & r4 & ")/(=sum(" & r1 & ":" & r2 & ")/100)"
ActiveCell.formula = per1

It's sticking at the final line. When you look at the Excel file, the
correct cell is selected, but the value's not there.

"Josie" wrote:

I'm new to writing code from scratch and I'm struggling with something.

Basically I have a row of numbers and beneath it I need a row which is the %
value that the number above is of the leftmost number. ie:

50 42 8
84 16

The row is a different number on every sheet so I can't use specific cell
references. I've managed to name all the cells that's not the problem, but
I'm unsure of the syntax for the mathmatical formula.

per1 = (p2 / (p1 / 100)) where p2 and p1 are names of cells, and per1 is a
string isn't working.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Udo Udo is offline
external usenet poster
 
Posts: 48
Default writing formulas in VB - referring to the values contained in cell

Hi Josie,

given your r1 through r4 are variables, the following should work:
Dim R1 As String
Dim R2 As String
Dim R3 As String
Dim R4 As String
Dim per1 As String

R1 = "B4"
R2 = "H4"
R3 = "B8"
R4 = "H5"

per1 = "=sum(" & R3 & ":" & R4 & ")/(sum(" & R1 & ":" & R2 & ")/100)"
ActiveCell.Formula = per1

Good luck
Udo

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default writing formulas in VB - referring to the values contained in

Thanks Udo, but it's not working. I have a friend who's relatively good at
this stuff, and he can't figure out what's wrong either. Driving me CRAZY.

"Udo" wrote:

Hi Josie,

given your r1 through r4 are variables, the following should work:
Dim R1 As String
Dim R2 As String
Dim R3 As String
Dim R4 As String
Dim per1 As String

R1 = "B4"
R2 = "H4"
R3 = "B8"
R4 = "H5"

per1 = "=sum(" & R3 & ":" & R4 & ")/(sum(" & R1 & ":" & R2 & ")/100)"
ActiveCell.Formula = per1

Good luck
Udo


  #5   Report Post  
Posted to microsoft.public.excel.programming
ers ers is offline
external usenet poster
 
Posts: 3
Default writing formulas in VB - referring to the values contained in

Hi Josie,

for few days I was looking for a way to reference in VBA a cell in
another sheet.
Only after I red this posting(s) I figure out the proper syntax. It
wasn't working when the reference cell was in another workbook.
The following is just to select a cell in sheet "c" knowing the column
which is mentionated in a cell (A1) in sheet "a".
Maybe will help in your situation.

Sub findcell()
Dim CN
CN = ThisWorkbook.Sheets("a").Range("A1").Value
'
Sheets("c").Select
Cells(1, CN).Select
End Sub

Good Luck
emil

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a list of formulas contained in a Workbook covingj Excel Discussion (Misc queries) 3 February 23rd 10 07:06 PM
Referring to sheets in formulas DaveAsh Excel Discussion (Misc queries) 0 May 14th 08 02:22 PM
Sum values referring to a cell with same value ghnogueira Excel Discussion (Misc queries) 3 March 23rd 07 09:11 PM
how can I imbed sheet names contained in cells into formulas? Ted Excel Worksheet Functions 2 March 8th 06 09:56 PM
referring to other cells with formulas ALex Excel Worksheet Functions 1 April 11th 05 05:14 PM


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"