Are ranges in VBA not accepting Double declared value?
I have the following code where I pick a value from a named range and store it in a variable declared as a Double. Later on, after changing the variable or not I want to reassign it to the named range. But here I get an Overflow error. The error disappears if I change the variable into an Integer. For information, I am working on a Mac.
'''
Dim maxDepth As Double
i=0
Do Until Range("scopeID").offset(i, 0) = ""
maxDepth = Range("currentDepth").offset(i, 0)
' some code here that possibly changes the value based on some conditions
Range("currentDepth").offset(i, 0) = maxDepth
i = i + 1
Loop
'''
do you know?
how many words do you know
See also questions close to this topic
-
.Body & .HTMLBody Indent and Default Signature Issue
I've set up a macro to send an e-mail through Outlook.
.Body is read from a cell inside the file with indents. Since the value will change depending on the usage, I need to reference that cell for the body.
However, there rises 2 issues using .HTMLbody I lose indents which are constructed with CHAR(10) but I keep the default HTML signature.
When using just .BODY indents are displayed are correctly however the default signature is not constructed as HTML and I lose the images.
How should I go about fixing this issue?
My code:
sig = .HTMLBody body = xlSht.Range("B4").Value .To = xlSht.Range("B2").Value .CC = "" .Subject = xlSht.Range("B1").Value .body = body & sig .Display
I'd really appreciate your assistance.
Thanks.
-
VBA: Creating a class property that is an array of dictionaries
In Microsoft Excel VBA I need to create a class that has two properties, "Name" and "Holdings". "Name" is just a string so the code for that is easy. But I need "Holdings" to be a variable length array containing dictionary objects. So this is what I wrote:
Private mName As String Private mHoldings() As Scripting.Dictionary Public Property Let Name(vName As String) mName = vName End Property Public Property Get Name() As String Name = mName End Property Public Property Set Holdings(vHoldings() As Scripting.Dictionary) Set mHoldings = vHoldings End Property Public Property Get Holdings() As Scripting.Dictionary Set Holdings = mHoldings End Property
When I try to compile it gives me this error: "Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalide Set final parameter.
What I doing wrong?
-
Yahoo Finance no longer returns VBA cookie request for .getResponseHeader("Set-Cookie")
The following Excel VBA code segment has worked for years, but stopped working around 28 Apr 2022. I receive the responseText, but the .getResponseHeader("Set-Cookie") returns null.
Set httpReq = New WinHttp.WinHttpRequest DownloadURL = "https://finance.yahoo.com/lookup?s=" & stockSymbol With httpReq .Open "GET", DownloadURL, False .setRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" .Send .waitForResponse response = .responseText cookie = Split(.getResponseHeader("Set-Cookie"), ";")(0) End With
-
Trying to calculate a 1hr range within the last 12hrs of a range with VBA
So I am trying to calculate a test temp for 1hr from the last 12 hours of data. Sometimes this data can be several days some times it can be only 24hrs. The statements seem to select the 1hr range within the last 12 of the data set, however the formula in J3 returns a -1 no matter what the data is. If I fill column J with value 5 for 300 rows it was returning -1. Some iterations of the code I tried were returning 0. Each row is 5 minutes so that is where the offset values come from for the 1hr.
This is what I have so far, and I am not sure what the issue is. I am very new to VBA.
Sub TestTemp_Cal() Dim LastRow As Long Dim HrRng As Long 'Selecting the 1hr range in the last 12 hrs of data LastRow = Application.ActiveSheet.Range("J6").End(xlDown).Select HrRng = Range(ActiveCell.Offset(-27, 0), ActiveCell.Offset(-39, 0)).Select 'Calculating the Test Temp Range("J3").Formula = "=ROUND(AVERAGE(" & HrRng & "),0)" End Sub
Would love some insight on this.
-
Range Not Found, Google Apps Script for Google Sheets
I'm trying to build a custom range for this sort function in an Apps Script for Google Sheets but I keep getting the error: "Exception: Range not found; sortProductionLog @ macros.gs:15"
I'm sure this is something basic but I have searched far and wide and can't seem to find it. Can anyone shed some light?
Thank you, Ryan
SORT_ORDER = [ {column: 118, ascending: true}, // 3 = column number, sorting by descending order {column: 119, ascending: true}, // 1 = column number, sort by ascending order {column: 117, ascending: true}, {column: 25, ascending: true} ]; function sortProductionLog(){ var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName(SHEET_NAME); var LastRow_WithValue = sheet.getLastRow(); var LastColumn_WithValue = sheet.getLastColumn(); var buildRange = "4,1," + (LastRow_WithValue - 4) + "," + (LastColumn_WithValue - 1); var range = sheet.getRange(buildRange); ss.toast(buildRange); range.sort }
-
How to return the range of values shared between two data frames in R?
I have several data frames that have the same columns names, and
ID
, the following to are the startfrom
and endto
of a range andgroup
label from each of them.What I want is to find which values of
from
andto
from one of thedata frames
are included in the range of the other one. I leave an example picture to ilustrate what I want to achieve (no graph is need for the moment)I thought I could accomplish this using
between()
of thedplyr package
but no. This could be accomplish using ifbetween()
returns true then return the maximum value offrom
and the minimum value ofto
between the data frames.I leave example data frames and the
results
I'm willing to obtain.a <- data.frame(ID = c(1,1,1,2,2,2,3,3,3),from=c(1,500,1000,1,500,1000,1,500,1000), to=c(400,900,1400,400,900,1400,400,900,1400),group=rep("a",9)) b <- data.frame(ID = c(1,1,1,2,2,2,3,3,3),from=c(300,1200,1900,1400,2800,3700,1300,2500,3500), to=c(500,1500,2000,2500,3000,3900,1400,2800,3900),group=rep("b",9)) results <- data.frame(ID = c(1,1,1,2,3),from=c(300,500,1200,1400,1300), to=c(400,500,1400,1400,1400),group=rep("a, b",5))
I tried using this function which will return me the values when there is a match but it doesn't return me the range shared between them
f <- function(vec, id) { if(length(.x <- which(vec >= a$from & vec <= a$to & id == a$ID))) .x else NA } b$fromA <- a$from[mapply(f, b$from, b$ID)] b$toA <- a$to[mapply(f, b$to, b$ID)]
-
How to check if double is NEGATIVE_INFINITY in Java
How do I check if double is NEGATIVE_INFINITY and not POSITIVE_INFINITY? There is only one method in Double class
isInfinite()
which checks whether the double is infinite or not but it returns true in both cases if it's positive and if it's negative. So is there another way to check the specific infinity (negative or positive)? -
How to write millions of double values into a txt file
I've made a neural network and now I need to save the results of the training process into a local file. In total, there are 7,155,264 values. I've tried with a loop like this
string weightsString = ""; string biasesString = ""; for (int l = 1; l < layers.Length; l++) { for (int j = 0; j < layers[l].Length; j++) { for (int k = 0; k < layers[l - 1].Length; k++) { weightsString += weights[l][j, k] + "\n"; } biasesString += biases[l][j] + "\n"; } } File.WriteAllText(@"path", weightsString + "\n" + biasesString);
But it literally takes forever to go through all of the values. Is there no way to write the contents directly without having to write them in a string first?
(Weights is a double[][,] while biases is a double[][])
-
How do I compute these to make my BMI Calculator work?
String A; String B; Double num1, num2; System.out.print("Enter your weight in kg: "); A = br.readLine(); num1 = Double.parseDouble(A); System.out.print("Enter your height in cm: "); B = br.readLine(); num2 = Double.parseDouble(B); **double bmi = (100 * 100 * A) / (B * B);** System.out.println("" + bmi); if (bmi < 18.5) { System.out.println("You are underweight"); } else if (bmi < 25) { System.out.println("You are normal"); } else if (bmi < 30) { System.out.println("You are overweight"); } else { System.out.println("You are obese"); } }
I think the problem is in this line, how do i compute these so it works? TIA! :double bmi = (100 * 100 * A) / (B * B);
-
Force compiler to use static definition from a specific C file
Two C files have the same variable name declared differently.
Can I force the compiler (Visual Studio or gcc) to prefer one declaration over the other?
The scenario is that I have a C file where I would not like to change anything and my own C file with several overlapping definitions, and that's where I would like to make my changes.
For example, I have the following definition in the original c file :
static unsigned char key[27 + 1] = "<put ur key here>";
And I have the following definition in my own c file :
static unsigned char key[27 + 1] = "abcde...";
When compiling, I would like the compiler to use my declaration instead of the original cpp file.
-
Inline out-of-class member function definition
struct S { void foo(); }; inline void S::foo() {}
Can't figure out from the documentation if this function is considered inline or not. We use the
inline
keyword but in the definition of a function previously declared as non-inline. What about the following case?struct S { inline void foo(); }; void S::foo() {}
-
declaration position problem in Javascript using Node.js
I wonder why the position of the declaration of variable matters in my code. It doesn't work depending on two different block scopes. Where can I get an idea to understand it?
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let input = []; rl.on('line', (line) => { input.push(line); // place these a, b, T, twoString declaration work correctly let a; let b; let T; let twoString = []; }).on('close', () => { // but I don't know why it doesn't work if I declare them in here T = Number(input[0]); for (let i = 1; i <= 5; i++) { twoString = input[i].split(' '); a = Number(twoString[0]); b = Number(twoString[1]); console.log(a + b); } }); // // This is input example // 5 // 1 1 // 2 3 // 3 4 // 9 8 // 5 2