mwahlgreen
New Member
- Joined
- Dec 21, 2018
- Messages
- 3
Hey forum
I am trying to do many things in my program for analysing a dataset. However I have run into some kind of wall. I will need help from you guys.
I started of making a lot of code where I have hard coded some ranges into the program.
These ranges tells the program where it should find data, labels, title, and stuff from my test dataset.
This part runs as a charm and produces eight fine looking graphs in a new sheet if I load my test data into the first sheet.
(Runs as one macro)
In another macro, I now want to write code that can input these ranges by asking for how many datasets are in a file
When it works I will implement it into the first marco.
First question for the user is "Write how many dataset there are", which via an Application.InputBox returns a number (integer).
So fare so good. Some of the error handling is not working as I would like to (I do not seem to be able to handle the Cancel button)
I have implemented this code, however this is seems to always go into the Else-statement for some unknown reason (the StrPtr(varNum) returns something else than 0 if Cancel is pushed.)
I can live with the issue of not handling the "errors", and this is not my main issue.
Now, when I have the number of dataset in my file, I would like to run a For loop for each dataset where I let the user select the range of rows in which the data is saved in different columns:
The output of the above is a variant array, which I fail to translate back to the ranges I need to continue forward.
What I need is the start cell for each of the input ranges and the height of each input ranges, then I can reconstruct the ranges to input into my script for the graphs.
This can be done by
However I do not have a range object, but a variant
If I try to read the variant (rngDataset(1)) into something else (a rangeObject):
or simply
I get various errors simply because I do not understand what I am doing to change the information in the variant array back to something I can use properly.
I hope someone can help me a that I make myself clear
Another path
Now the above is one approach. Another approach could be as the following.
Pseudocode
I will continue on the second option for now, however I would really like to know if the first option is possible to solve and if I was taking my program in the right direction. I spend at least day on it and I am sad to just let it go without knowing what went wrong.
If someone want to see my full code I can post both this and a data file for testing, without letting any cats out of the bag according to my firms knowledge or similar. Just ask.
I am trying to do many things in my program for analysing a dataset. However I have run into some kind of wall. I will need help from you guys.
I started of making a lot of code where I have hard coded some ranges into the program.
These ranges tells the program where it should find data, labels, title, and stuff from my test dataset.
This part runs as a charm and produces eight fine looking graphs in a new sheet if I load my test data into the first sheet.
(Runs as one macro)
In another macro, I now want to write code that can input these ranges by asking for how many datasets are in a file
When it works I will implement it into the first marco.
First question for the user is "Write how many dataset there are", which via an Application.InputBox returns a number (integer).
So fare so good. Some of the error handling is not working as I would like to (I do not seem to be able to handle the Cancel button)
I have implemented this code, however this is seems to always go into the Else-statement for some unknown reason (the StrPtr(varNum) returns something else than 0 if Cancel is pushed.)
Code:
Dim varNum As Variant
'...
varNum = Application.InputBox("Write how many dataset there are (max 15)", "Obtain the number of datasets in this spreadsheet", "1", , , , , 1)
If StrPtr(varNum) = 0 Then
'StatementsIfCancel
ElseIf varNum = "" Then
'StatementsIfNoInput
'Else
'StatementsIfInputAndOK
End If
Now, when I have the number of dataset in my file, I would like to run a For loop for each dataset where I let the user select the range of rows in which the data is saved in different columns:
Code:
Dim intNum as Integer
Dim rngDataset(15) as Variant
'...
For i = 1 To intNum
rngDataset(i) = Application.InputBox("Select a range (no. " & i & ")", "Obtain Range Object", , , , , , 8)
'Same error handling as above here, still not working
Next i
The output of the above is a variant array, which I fail to translate back to the ranges I need to continue forward.
What I need is the start cell for each of the input ranges and the height of each input ranges, then I can reconstruct the ranges to input into my script for the graphs.
This can be done by
Code:
rangeObject.Row
rangeObject.Row.Count
If I try to read the variant (rngDataset(1)) into something else (a rangeObject):
Code:
Dim rng As Range'...
Set rng = rngDataset(1)
Code:
Dim rng As Range
'...
rng = rngDataset(1)
I hope someone can help me a that I make myself clear
Another path
Now the above is one approach. Another approach could be as the following.
Pseudocode
Code:
For.....
Extract Range using Inputbox (E.g. i=1 A2:A11 i=2 A12:A21)
Extract first row of that range and store it one array (string)
Extract Row.count of that range and store it another array (string)
Next i
... Do something else ...
'Reconstruct the ranges with data
For i
i=1
Look for labels in B2:B11
Look for data for Series1 in CV2:CV11
Look for data for Series2 in CW2:CW11
Look for data for Series3 in CX2:CX11
Look for data for Series4 in CY2:CY11
i=2
Look for labels in B12:B21
Look for data for Series1 in CV12:CV21
Look for data for Series2 in CW12:CW21
Look for data for Series3 in CX12:CX21
Look for data for Series4 in CY12:CY21
Next i
I will continue on the second option for now, however I would really like to know if the first option is possible to solve and if I was taking my program in the right direction. I spend at least day on it and I am sad to just let it go without knowing what went wrong.
If someone want to see my full code I can post both this and a data file for testing, without letting any cats out of the bag according to my firms knowledge or similar. Just ask.