-
#2
This sounds as though you should look to set the queries in the database then run the queries from Excel.
If you don’t want to extract data from the database into Excel why would you want to use Excel Formula when Access Formula should do what you want?
-
#3
I want Excel to act as a Dashboard, so I will create and layout different charts in the workbook. I dont know much of ACCESS capabilities; could I create the charts from there and then link them to Excel?
The end-user is only having access to Excel, the Access database should solely be used to build the charts, and Excel should retrieve the end product.
-
#4
I want Excel to act as a Dashboard, so I will create and layout different charts in the workbook. I dont know much of ACCESS capabilities; could I create the charts from there and then link them to Excel?
The end-user is only having access to Excel, the Access database should solely be used to build the charts, and Excel should retrieve the end product.
Look to utilise queries in Access then bring in the end result or use the External Data in Excel and create a query then save the query if it works for you then look to record a macro to run the query and that should work.
-
#5
Thanks for your advice Trevor; even with SQL queries to retrieve the data, I would be storing it in Excel at some point right? What do you mean when talking about external data in Excel? Is it possible to create a direct link from Excel to Access? If I have to store the data in Excel at some stage, I may as well store the data directly in Excel and forget about Access.
I have to say that I had higher expectations about the possibilities Access can deliver, but it seems like its only really useful as a Database if several users are using the data for different purposes. Though I think Excel should not be used to store large quantities of Data, I don’t see the point of going through the hassle of using Access if you need to copy/paste the data to Excel, and delete the data once exploited.
Cheers.
Last edited: Jun 7, 2013
-
#6
Thanks for your advice Trevor; even with SQL queries to retrieve the data, I would be storing it in Excel at some point right? What do you mean when talking about external data in Excel? Is it possible to create a direct link from Excel to Access? If I have to store the data in Excel at some stage, I may as well store the data directly in Excel and forget about Access.
I have to say that I had higher expectations about the possibilities Access can deliver, but it seems like its only really useful as a Database if several users are using the data for different purposes. Though I think Excel should not be used to store large quantities of Data, I don’t see the point of going through the hassle of using Access if you need to copy/paste the data to Excel, and delete the data once exploited.
Cheers.
Did you find out how to do this?
I agree with you in that I do not want to pull an entire table from Access into my Excel file just so I can get data from it. It makes the file way to big. I want a formula that would lookup a customer name from an Access table based on a customer number in Excel.
-
#7
Did you find out how to do this?
I agree with you in that I do not want to pull an entire table from Access into my Excel file just so I can get data from it. It makes the file way to big. I want a formula that would lookup a customer name from an Access table based on a customer number in Excel.
Hi Mike,
This post is not that recent but if I recall correctly the issue was IF it was possible to use Excel’s built-in formulas to query an Access Data Base directly. Unfortunately you cannot and need to use SQL queries or similar methods.
You can build SQL queries from Acces, Miscrosoft SQL query builder or manually.
Hope this helps.
-
#8
Hi Mike,
This post is not that recent but if I recall correctly the issue was IF it was possible to use Excel’s built-in formulas to query an Access Data Base directly. Unfortunately you cannot and need to use SQL queries or similar methods.
You can build SQL queries from Acces, Miscrosoft SQL query builder or manually.
Hope this helps.
That helps, Zaza. Thank you.
FormulaR1C1
is the method of how the formula is written.
Formula
refers to writing a formula in A1 like =B1+C1
.
To write that same formula using R1C1
notation, you would write =RC[1] + RC[2]
. Furthermore to write =B2+C2
in A1 write this =R[1]C[1] + R[1]C[2]
-> so you can see you are offsetting the columns and rows where you want the formula to return values from.
What you want to do in your code is offset the place where the formula will be placed, rather than how it’s calculating, so you should write this:
.ActiveCell.Offset(,1).Formula = strExcel
Actually, you should get rid of ActiveCell
altogether, unless you absolutely need it.
I would write your code like this for better, more accurate execution:
Dim Excel_App As Object
Dim strExcel As String
Dim wkb as Object, wks as Object
Set Excel_App = CreateObject("Excel.Application")
Excel_App.Visible = True
Set wkb = Excel_App.Workbooks.Add
Set wks = wkb.Sheets(1) 'assumes you want first sheet, can modify for sheet index or name
With wks
.Range("A:B").EntireRow.ColumnWidth = 25
'I think this will actually set every row to 25, is that what you want?
.Range("A2").EntireRow.Font.FontStyle = "Bold"
.Range("A1").Value = "ABC" 'don't need to write Value, but just to show you the property
strExcel = "=IF(A1 = """"," & """EMPTY""" & "," & """FILLED""" & ") "
.Range("B1").Formula = strExcel
End With
This MSAccess tutorial explains how to convert Excel formulas to Access with an example in Access 2003 (with step-by-step instructions).
Question: In Microsoft Access 2003/XP/2000/97, I’m trying to build an expression that will do the same as the following Excel formula with the result formatted as «dd/mm/yyyy».
=VALUE(DATE(VALUE(MID(A1,4,1))+2000,1,1))+VALUE(MID(A1,5,3))-1
How can I do this?
Answer: In an Access query, the equivalent formula would be:
Format(DateSerial(Val(Mid([Field1],4,1))+2000,1,1)+Val(Mid([Field1],5,3))-1,"dd/mm/yyyy")
This formula uses the Format function, DateSerial function, Val function, and Mid function in Access. We’ve also replaced the reference to cell A1 with Field1.
Содержание
- 1 Assigns the values 101 to 200 to the range B1:Bnd again does it more efficiently than a For…Next loop
- 2 Create a set of related formulas in a column: use a looping structure to iterate through the cells that receive the formula
- 3 Fill formula to cell
- 4 Inserts a formula in cell A11 of a worksheet that calculates the sum of the values in the range A2:A10 using the Excel application»s SUM function
- 5 Is active cell empty
- 6 The Evaluate method can also be used with arrays.
- 7 Two ways you can use Evaluate to generate a reference to a Range object, and assign a value to that object
- 8 Use Copy and Paste or AutoFill functions
- 9 Use [] to evaluate formula
Assigns the values 101 to 200 to the range B1:Bnd again does it more efficiently than a For…Next loop
<source lang="vb">
Sub main()
[B1:B100] = [ROW(101:200)]
End Sub
</source>
Create a set of related formulas in a column: use a looping structure to iterate through the cells that receive the formula
<source lang="vb">
Sub formula()
Dim formulaString As String Dim I As Integer Cells(1, "B").Value = Cells(1, "A").Value For I = 2 To 10 formulaString = "=A" & Trim(str(I)) & "+B" & Trim(str(I - 1)) Cells(I, "B").formula = formulaString Next I
End Sub
</source>
Fill formula to cell
<source lang="vb">
Sub AddWatch()
With Application .Range("A1").Formula = 1 .Range("A2").Formula = 2 .Range("A3").Formula = "=Sum(A1:A2)" .Range("A3").Select .Watches.Add Source:=ActiveCell End With
End Sub
</source>
Inserts a formula in cell A11 of a worksheet that calculates the sum of the values in the range A2:A10 using the Excel application»s SUM function
<source lang="vb">
Sub formal()
Dim formulaString As String formulaString = "=SUM($A$2:$A$10)" Cells(11, "A").Formula = formulaString
End Sub
</source>
Is active cell empty
<source lang="vb"> Sub IsActiveCellEmpty() Dim sFunctionName As String, sCellReference As String sFunctionName = "ISBLANK" sCellReference = ActiveCell.Address MsgBox Evaluate(sFunctionName & "(" & sCellReference & ")") End Sub </source>
The Evaluate method can also be used with arrays.
<source lang="vb">
Sub short()
vRowArray = [ROW(101:200)]
End Sub
</source>
Two ways you can use Evaluate to generate a reference to a Range object, and assign a value to that object
<source lang="vb">
Sub evalDemo()
Evaluate("A1").value = 10 [A1].value = 10
End Sub
</source>
Use Copy and Paste or AutoFill functions
<source lang="vb">
Sub autoFill()
Dim formulaString As String Dim I As Integer Cells(1, "B").Value = Cells(1, "A").Value formulaString = "=A2+B1" Cells(2, "B").formula = formulaString
End Sub
</source>
Use [] to evaluate formula
<source lang="vb">
Sub isBlank()
MsgBox [ISBLANK(A1)]
End Sub
</source>
In addition to dealing with the Excel objects, understanding how to use R1C1 format to write formulas makes coding much easier. For example, subtracting the cell one row above from the cell two rows above is very straightforward when using R1C1 notation . If you use A1 notation, you have to go through multiple steps to write the string. First, figure out what column and row you are in, and then turn the column number into a letter. Next, create strings by concatenating the column letter with the row numbers needed for your formula. Doing this for several columns would get tiresome, not to mention difficult to follow. You could also perform the calculation in VBA by using the row and column numbers with the Cells object, resulting in a fixed value instead of a formula. This is likely not what you want for most reporting because it can lead to inconsistent information if the original numbers are changed. Using the R1C1 format, you refer to the other cells by the number of rows or columns in relation to the current cell. In the previous example, the formula in R1C1 notation would be = R[-2]C — R[-1]C, which calculates the cell.
Excel uses R1C1 notation to refer to a cell by the row and column numbers. For example, cell B10 is in column 2 and row 10; refer to this as R10C2 by using R1C1 notation. R1C1 notation also allows you to refer to a cell in relation to the current cell when writing a formula. Instead of placing a number for the row or column, you can place a number in brackets after R or C to move the specified number of columns or rows to refer to the cell you want. When you use a number for the row or column, Excel shows it as a fixed reference by using a $ in the formula. You can also refer to the row and column with a fixed reference for one and a relative reference for the other. R2C[-1] would refer to the second row of the column to the left of the current cell. |
When you write formulas, there are several properties that you can set to write the formula or value (see Table 8-1). This chapter covers Formula, FormulaR1C1, and FormulaArray, which provide most of the functionality that you need.
Property |
Description |
---|---|
Formula |
Returns or sets a formula using A1-style notation |
FormulaArray |
Returns or sets an array formula using R1C1-style notation |
FormulaLocal |
Returns or sets a formula using A1-style notation in the language of the user |
FormulaR1C1 |
Returns or sets a formula using R1C1-style notation |
FormulaR1C1Local |
Returns or sets a formula using R1C1-style notation in the language of the user |
Value |
Returns or sets a fixed value |
Let’s look at returning R1C1 formula values so that you can get a feel for how to write them. Specifically, you need to understand how to set fixed and relative references. Look at the formulas in Figure 8-1, shown in A1-style notation below each result. Create a workbook similar to this one and press Alt+F11 to go to the Visual Basic Editor. Then, press Ctrl-G to go to Immediate Window.
The first formula to look at is cell B5, also shown as text in cell B6 in Figure 8-1. In this formula, use relative references so that if you copy them from left to right, they update to the correct formula. If you copy them down, this formula will not yield the correct result. Type the following line in the immediate window, and it shows you how to write this formula in R1C1-style notation:
? sheets("Sheet1").Range("B5").FormulaR1C1
The result comes back =R[-3]C-R[-2]C for the A1-style formula of =B2-B3. This R1C1-style formula works in any of the cells in row 5. Breaking down this formula, it tells Excel to subtract the cell two rows up in the current column from the cell three rows
Figure 8-1. The worksheet showing similar formulas written a variety of different ways
up in the current column. Next, look at the formula in cell C5. Type the following line in the immediate window:
? sheets("Sheet1").Range("C5").FormulaR1C1
This formula result comes back =R2C3-R3C3 for the A1-style formula of =$C$2-$C$3. For this formula, the exact same A1-style formula result comes back regardless of the cell being because the formula tells Excel to subtract row 3 column 3 (C3) from row 2 column 3 (C2). When using R1C1 notation, whenever you use a row or column number and do not put it in brackets, it results in the row or column being preceded by a $ in the formula. When a $ is used in A1-style notation, Excel creates a fixed reference. If you copy a formula with fixed references, the portion with the $ will not change, regardless of where you copy it. This is important to keep in mind as you decide how to write the formula. Type the following line in the immediate window:
? sheets("Sheet1").Range("D5").FormulaR1C1
The formula result comes back =R2C-R3C4 for the A1-style formula of =D$2-$D$3. Notice that in this formula, dollar signs precede everything except the D in the first cell reference in the formula. Looking at the R1C1-style notation, you see that the column reference uses the current column C. If you put a number after the column reference, it returns the column with a dollar sign. Look at the others as well, but for the next formula, look at B8. Type the following line in the immediate window:
? sheets("Sheet1").Range("B8").FormulaR1C1
The formula results come back =SUM(R5C2:R[-3]C) for the A1-style formula of =SUM($B$5:B5). This formula is important because same R1C1-style formula comes back for the entire row. This is the easiest way to write a running sum using a fixed reference for the beginning of the sum range and a relative reference for the end of the range. If you copy the formula across, it returns the correct formula for the running sum for each column.
Certainly look at the other formulas; looking at the resulting R1C1 formulas should help you write them yourself. I strongly encourage you to use this technique to write more complex formulas, since it is much easier to create the formula in the Excel GUI than to write it yourself.