I am trying to find help to an Access Error I receive when Importing from an xls spreadsheet.
I am using Access 2010 and Excel 2010
The error only happens in blank cells that are formatted as Accounting with a value of 0.00 hard coded into the formula for all blank cells. I have changed the cell format to number (and the value to 0), and even replaced the values with "" (To make them null).
Before import I repaste values only (Paste special values only) over the formulas so that all the number data is value only.
For the Import I am replacing an existing table in access each time (Its the way its designed not my idea) so I am not sure if this might have any affect. When I run the import only the 0.00 number fields are put into the error table.
I have been trying to work with the .value = .value commands in VBA talked about other places on this board, but I have had no luck so far. Any help or ideas on the subject would be great.
Thank you,
Daniel
First, run this code on the Excel worksheet.
sub cleanup
dim c as long
with worksheets("sheet1").cells(1, 1).currentregion
for c = 1 to .columns.count
.columns(c).cells = .columns(c).cells.value2
next c
end with
end sub
Set the Access monetary fields to Currency. Allow Required: No with a Default value: 0.
The Excel worksheet cells cannot be zero-length strings (e.g. ""). They have to be truly blank. That is taken care of with the short cleanup routine. The truly blank cells will come into the Access field as nulls and receive the default value of 0.
Related
I want to ask whether it is possible to have excel print out a complete row of raw data using two variables. So like let say we have the following data:
What we wish to have is that based on the values "2018" and "A", excel should give out the complete row data automatically as done so in the yellow cells.
I know how to do it for one variable, where I have been using
Index(range,MATCH(value, range,0),column())
But I am having difficulty when there are two unique variables, based on which the row data must be extracted.
Currently, I do it in two steps. So I first filter out the year and then use the above formula to extract the row data for A or B. But it is not a very good approach and would appreciate if it can be done using a single formula.
Does anyone has any clue on how it can be done without using Pivot Table?
UPDATE
Regarding the suggestion of using VBA. Using the VBA is a good option, since then I can just use the autofilter command, but the problem is defining the cells in VBA and also how can I have one code for two different columns?
My vba code which I have used for filtering the tables is the following:
Sub Autofilter_Filter12()
Dim lo as ListObject
Dim iCol As Long
Set lo = Sheet3.Listobjects(1)
iCol = lo.ListColumns("Year").Index
with lo.Range
.Autofilter Field:=iCol, Criterial:="XXXX"
End Sub
Now the problem with the VBA code is:
it is only applied for one column and not both.
Instead of XXX, how can I define a cell into the VBA? I have tried but failed again and again.
Thank you for the help.
If range C:H is always numbers then you can use SUMPRODUCT.
=SUMPRODUCT(($A$2:$A$5=$A$7)*($B$2:$B$5=$B$7)*C2:C5)
parameter 1 parameter 2 Value to return
In C7, then select C7:H7 and press CTRL+R.
This results in this:
When this fails it will return 0.
Not very nice, but it could be partially solved with I7 =
=IFERROR(IF(SUM(C7:H7)=0,"Filter failed",""),"")
In EXCEL 365 with dynamic formula you can put multiple columns in MATCH formula by merging them with &
=MATCH(A7&B7,A1:A6&B1:B6,0)
So you can use index-match combination for your case (no matter if values are nubmers or not):
=INDEX(C$1:C$6,MATCH($A$7&$B$7,$A$1:$A$6&$B$1:$B$6,0))
We have a spreadsheet that's being generated by another system that provides data in Milliseconds, but I need to convert it to something that's easier to digest for the business.
I'm looking for an easy way to get it converted to duration HH:MM:SS - the columns to be converted aren't always the same columns so I'd need to be able to select certain columns and then do the conversion.
Any help is greatly appreciated - I played a bit with the macros in Excel, but it's been years since I programmed and I wasn't sure how to do some of the relative mappings for the equations.
Thanks!
Select a contiguous group of cells containing millisecond values as long integers.
Run the convertSelection sub procedure.
Select another contiguous group of cells.
Go to step 2.
Remember to put this code into a public module code sheet first.
Sub convertSelection()
With Selection
.Value = Application.Evaluate(.Address & "/86400000")
.NumberFormat = "hh:mm:ss.000"
End With
End Sub
In Excel 2010, I am writing VBA to take the SUM of a range of filtered values, and store that result into a variable. The code looks like this:
With Sheets("Output")
.Range("$A:$ZZ").AutoFilter field:=ColIndex(AB), Criteria1:="x"
y = Application.WorksheetFunction.Sum( _
Range(Cells(2, "AC"), Cells(10, "AC")).SpecialCells(xlCellTypeVisible) _
)
This does work, but only when I have manually toyed with the data. When I try to use this formula on my data set unedited, I get a blank result. The problem seems to lie with the data when unedited.
Each number gets the Number Stored as Text (NSaT) error. Changing the type from Text to General causes nothing to happen. I have to open the cell for editing, and then remove focus from the cell for the type to kick in. After that, I can change it back and forth from General to Text, and Excel immediately recognizes this and updates the cell. The Sum function will, at this point, recognize both General and Text field types as a number.
Is there a VBA solution for dealing with these NSaT errors? I have attempted to use 'NumberFormat' on the column, but it does not help. I have also tried manually copying and pasting the data again, even using the special As Value option, but it still has the NSaT error until manually toyed with.
I tried searching for this, but I kept coming across questions of how to make a cell show as blank instead of false. I want to clear the formula out.
I am working from an access database (that i can't do much to), that contains data on sessions on our computers. What the database will give me currently is basically "Section 1, 9-10", "Section 1, 10-11", etc. There are a total of 5 sections like this for 11 hours. In the past, I've had to copy from those queries into excel sheets. What I've gotten to at this point is I can create a query for each section that just gives me the information I need, start time and duration, which I can paste into a workbook I made.
What this workbook does is take the data from those columns and moves it to page 2 sorted by hour with if statements. the problem with that is I need those if statements to go all the way across, and far enough down to be sure to include the highest number of sessions we've had, plus a comfortable buffer, so it's 7000 rows down.
After that sorting is done, I can take all the data from that second sheet and paste it into monthly records. the problem is, with there being formulas in each of those cells, it adds approximately 7-10 Mb to the file size.
Is there someway so that cells that evaluate to false have their formula removed? Or, probably more likely, a better way to go about this without much additional software?
I'm guessing you want to use an if formula and if it evaluates to False then display nothing. You can do this by setting the value for the false result to "".
=if(expression,value if true, "")
The alternative is to use a macro to loop through each cell and clear it if the value is false.
Sub falseToClear()
' Change to the range you need to parse
Set Rng = Sheets(1).UsedRange
For Each cell In Rng
If cell.Value = False Then cell.ClearContents
Next cell
End Sub
I have a series of array formulas in Excel that key off of each other. These are automatically resized to fit a range of data that is generated via a proprietary Excel add-in.
However, whenever my code rewrites some of the array formulas to the correct new size, the cells all show as #N/A until either you edit another unrelated cell on the sheet, save the sheet, or press F9.
Using code such as Application.Calculate, ActiveSheet.Calculate, etc do not have any effect.
However, using SendKeys "{F9}" does.
As an example, these are two formulas on the sheet:
={IF(LEN(INDEX(A:A, ROW()))>0,ROW(A:A)+2)}
and
={LARGE(OFFSET($J$1,0,0,ROW()),1)}
The first formula works fine after writing it programmatically to a range of cells. It merely tells me the row number of a cell that has text in it.
The second formula does not work after writing it programmatically to a range of cells. It gives me the largest row number that has been previously seen in a list of numbers (which is the output of the first formula). If I press F9, the second formula updates correctly. If I do Application.Calculate in VBA, nothing happens. I've also tried the various other recalculate methods available at the Worksheet level as well, but no luck.
Has anyone encountered something like this before?
edit:
The resize code essentially boils down to something like this (stripping out all of the support code that allows me to make more generalized calls to it):
First, I do:
formula = dataSheet.Cells(startRow, startColumn).formula
Then later:
Set DeleteRange = dataSheet.Range(dataSheet.Cells(startRow, startColumn), dataSheet.Cells(bottomBound, rightBound))
DeleteRange.ClearContents
Set DeleteRange = Nothing
Then later on:
Set resultRange = dataSheet.Range(dataSheet.Cells(startRow, startColumn), dataSheet.Cells(startRow + Height - 1, startColumn + Width - 1))
resultRange.FormulaArray = formula
Set resultRange = Nothing
In a nut shell, I make a copy of the formula, clear the range, then rewrite it.
If you can't beat 'em, join 'em.
SendKeys "{F9}"
I have fleshed out my comment above given you have implemented this approach
using this code
Dim strFormula As String
strFormula = "=LARGE(OFFSET($J$1,0,0,ROW()),1)"
Range("a1:a5").FormulaArray = strFormula
xl03 gives numbers but needs a calc to update the cells properly
xl07 gives the "#N/A" (and raises a Calculate in the statusbar)
xl10 works fine
As you point out none of the calculation options including a full dependency tree rebuild work
using my RAND suggestion above does force the update in xl07
Dim strFormula As String
strFormula = "=LARGE(OFFSET($J$1,0,0,ROW()),1)+ RAND()*0"
Range("a1:a5").FormulaArray = strFormula
OFFSET is a volatile function see Voltatile Excel Functions (which includes a file that tests volatility)
Perhaps Charles Williams can shed some light on this, I will ping him
Looks like a FormulaArray bug in 2003 and 2007.
A simpler bypass for your formula would be to use Range("a1:A5").Formula instead of formula array since =LARGE(OFFSET($J$1,0,0,ROW()),1) does not need to be an array formula
My recollection is that there is also an Application.CalculateFull method - does that work?
My cells were not refreshing after ranges they depended on were modified either.
I also had to hand edit each one to get them to re-calculate.
SOLUTION:
Use fully qualified references within your formulas.
e.g. any formulas that look like this YourFunction(G200:H700) should be changed to look like this YourFunction('Your Sheet Name'!G200:H700).
Auto-Refresh now works perfectly for me.