I`m trying to create array with value from activesheet (VBA)
I'm trying to create array with values from non-empty cells in range B6:B183 . array_articles = ActiveWorsheet.Range("B6:B183")
return empty array, so I'm trying to do this:
Sub set_price()
Dim articul_price() As String
Dim articul_bill As String
Dim counter As Integer
Dim array_articles() As Variant
Dim array_unsorted() As String
Dim cell As Range
counter = 0
ReDim articul_price(0)
For Each cell In ActiveWorsheet.Range("B6:B183") ' error 424 Object required
If IsEmpty(cell.Value) Then
array_unsorted(counter) = cell.Value
ReDim Preserve array_unsorted(counter)
Else
'do nothing
counter = counter + 1
End If
Next
End Sub
This code return
error 424 Object required
excel vba
add a comment |
I'm trying to create array with values from non-empty cells in range B6:B183 . array_articles = ActiveWorsheet.Range("B6:B183")
return empty array, so I'm trying to do this:
Sub set_price()
Dim articul_price() As String
Dim articul_bill As String
Dim counter As Integer
Dim array_articles() As Variant
Dim array_unsorted() As String
Dim cell As Range
counter = 0
ReDim articul_price(0)
For Each cell In ActiveWorsheet.Range("B6:B183") ' error 424 Object required
If IsEmpty(cell.Value) Then
array_unsorted(counter) = cell.Value
ReDim Preserve array_unsorted(counter)
Else
'do nothing
counter = counter + 1
End If
Next
End Sub
This code return
error 424 Object required
excel vba
1
You have a typo inActiveWorsheet
(missingk
) • But you can just doarray_unsorted = ActiveWorksheet.Range("B6:B183").Value
to load the range into an array (2-dimensional). If you want it 1-dimensional transpose the range:array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
– Pᴇʜ
Nov 21 '18 at 8:59
I'm trying to writeDim array_unsorted() As String ReDim array_unsorted(0 To 200) array_unsorted = ActiveWorksheet.Range("B6:B183").Value
but it still return empty array without data.array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
return the same.
– Lomil
Nov 21 '18 at 9:12
I posted it as an answer to make it more clear.
– Pᴇʜ
Nov 21 '18 at 9:27
add a comment |
I'm trying to create array with values from non-empty cells in range B6:B183 . array_articles = ActiveWorsheet.Range("B6:B183")
return empty array, so I'm trying to do this:
Sub set_price()
Dim articul_price() As String
Dim articul_bill As String
Dim counter As Integer
Dim array_articles() As Variant
Dim array_unsorted() As String
Dim cell As Range
counter = 0
ReDim articul_price(0)
For Each cell In ActiveWorsheet.Range("B6:B183") ' error 424 Object required
If IsEmpty(cell.Value) Then
array_unsorted(counter) = cell.Value
ReDim Preserve array_unsorted(counter)
Else
'do nothing
counter = counter + 1
End If
Next
End Sub
This code return
error 424 Object required
excel vba
I'm trying to create array with values from non-empty cells in range B6:B183 . array_articles = ActiveWorsheet.Range("B6:B183")
return empty array, so I'm trying to do this:
Sub set_price()
Dim articul_price() As String
Dim articul_bill As String
Dim counter As Integer
Dim array_articles() As Variant
Dim array_unsorted() As String
Dim cell As Range
counter = 0
ReDim articul_price(0)
For Each cell In ActiveWorsheet.Range("B6:B183") ' error 424 Object required
If IsEmpty(cell.Value) Then
array_unsorted(counter) = cell.Value
ReDim Preserve array_unsorted(counter)
Else
'do nothing
counter = counter + 1
End If
Next
End Sub
This code return
error 424 Object required
excel vba
excel vba
edited Nov 21 '18 at 8:58
Pᴇʜ
22.2k42750
22.2k42750
asked Nov 21 '18 at 8:57
LomilLomil
184
184
1
You have a typo inActiveWorsheet
(missingk
) • But you can just doarray_unsorted = ActiveWorksheet.Range("B6:B183").Value
to load the range into an array (2-dimensional). If you want it 1-dimensional transpose the range:array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
– Pᴇʜ
Nov 21 '18 at 8:59
I'm trying to writeDim array_unsorted() As String ReDim array_unsorted(0 To 200) array_unsorted = ActiveWorksheet.Range("B6:B183").Value
but it still return empty array without data.array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
return the same.
– Lomil
Nov 21 '18 at 9:12
I posted it as an answer to make it more clear.
– Pᴇʜ
Nov 21 '18 at 9:27
add a comment |
1
You have a typo inActiveWorsheet
(missingk
) • But you can just doarray_unsorted = ActiveWorksheet.Range("B6:B183").Value
to load the range into an array (2-dimensional). If you want it 1-dimensional transpose the range:array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
– Pᴇʜ
Nov 21 '18 at 8:59
I'm trying to writeDim array_unsorted() As String ReDim array_unsorted(0 To 200) array_unsorted = ActiveWorksheet.Range("B6:B183").Value
but it still return empty array without data.array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
return the same.
– Lomil
Nov 21 '18 at 9:12
I posted it as an answer to make it more clear.
– Pᴇʜ
Nov 21 '18 at 9:27
1
1
You have a typo in
ActiveWorsheet
(missing k
) • But you can just do array_unsorted = ActiveWorksheet.Range("B6:B183").Value
to load the range into an array (2-dimensional). If you want it 1-dimensional transpose the range: array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
– Pᴇʜ
Nov 21 '18 at 8:59
You have a typo in
ActiveWorsheet
(missing k
) • But you can just do array_unsorted = ActiveWorksheet.Range("B6:B183").Value
to load the range into an array (2-dimensional). If you want it 1-dimensional transpose the range: array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
– Pᴇʜ
Nov 21 '18 at 8:59
I'm trying to write
Dim array_unsorted() As String ReDim array_unsorted(0 To 200) array_unsorted = ActiveWorksheet.Range("B6:B183").Value
but it still return empty array without data. array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
return the same.– Lomil
Nov 21 '18 at 9:12
I'm trying to write
Dim array_unsorted() As String ReDim array_unsorted(0 To 200) array_unsorted = ActiveWorksheet.Range("B6:B183").Value
but it still return empty array without data. array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
return the same.– Lomil
Nov 21 '18 at 9:12
I posted it as an answer to make it more clear.
– Pᴇʜ
Nov 21 '18 at 9:27
I posted it as an answer to make it more clear.
– Pᴇʜ
Nov 21 '18 at 9:27
add a comment |
1 Answer
1
active
oldest
votes
To easily load a range into an array (without a loop) use:
Dim array_unsorted As Variant 'must be variant!
array_unsorted = ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value '2-dimensional array
you can access the array with
Debug.Print array_unsorted(row, column) 'yes it has only 1 column but it is still there
Debug.Print array_unsorted(1, 1) 'first value
Debug.Print array_unsorted(2, 1) 'second value
or transpose it to make it 1-dimensional
array_unsorted = WorksheetFunction.Transpose(ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value) '1-dimensional
and you can access the array with
Debug.Print array_unsorted(i) 'this is 1-dimensional
Debug.Print array_unsorted(1) 'first value
Debug.Print array_unsorted(2) 'second value
Note that the transpose function has a limit of 65,536 rows. If you exceed them the rest will be truncated silently.
I recommend to avoid ActiveWorksheet
(unless you write an add-in or the code is used for multiple worksheets). Use ThisWorkbook.Worksheets("NameOfSheet")
to reference the worksheet by its name, which is more save and Excel won't run into errors.
1
Variant for 2-dimensional array worked, thanks. I suggest that will be enough for this project.
– Lomil
Nov 21 '18 at 9:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408372%2fim-trying-to-create-array-with-value-from-activesheet-vba%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To easily load a range into an array (without a loop) use:
Dim array_unsorted As Variant 'must be variant!
array_unsorted = ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value '2-dimensional array
you can access the array with
Debug.Print array_unsorted(row, column) 'yes it has only 1 column but it is still there
Debug.Print array_unsorted(1, 1) 'first value
Debug.Print array_unsorted(2, 1) 'second value
or transpose it to make it 1-dimensional
array_unsorted = WorksheetFunction.Transpose(ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value) '1-dimensional
and you can access the array with
Debug.Print array_unsorted(i) 'this is 1-dimensional
Debug.Print array_unsorted(1) 'first value
Debug.Print array_unsorted(2) 'second value
Note that the transpose function has a limit of 65,536 rows. If you exceed them the rest will be truncated silently.
I recommend to avoid ActiveWorksheet
(unless you write an add-in or the code is used for multiple worksheets). Use ThisWorkbook.Worksheets("NameOfSheet")
to reference the worksheet by its name, which is more save and Excel won't run into errors.
1
Variant for 2-dimensional array worked, thanks. I suggest that will be enough for this project.
– Lomil
Nov 21 '18 at 9:30
add a comment |
To easily load a range into an array (without a loop) use:
Dim array_unsorted As Variant 'must be variant!
array_unsorted = ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value '2-dimensional array
you can access the array with
Debug.Print array_unsorted(row, column) 'yes it has only 1 column but it is still there
Debug.Print array_unsorted(1, 1) 'first value
Debug.Print array_unsorted(2, 1) 'second value
or transpose it to make it 1-dimensional
array_unsorted = WorksheetFunction.Transpose(ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value) '1-dimensional
and you can access the array with
Debug.Print array_unsorted(i) 'this is 1-dimensional
Debug.Print array_unsorted(1) 'first value
Debug.Print array_unsorted(2) 'second value
Note that the transpose function has a limit of 65,536 rows. If you exceed them the rest will be truncated silently.
I recommend to avoid ActiveWorksheet
(unless you write an add-in or the code is used for multiple worksheets). Use ThisWorkbook.Worksheets("NameOfSheet")
to reference the worksheet by its name, which is more save and Excel won't run into errors.
1
Variant for 2-dimensional array worked, thanks. I suggest that will be enough for this project.
– Lomil
Nov 21 '18 at 9:30
add a comment |
To easily load a range into an array (without a loop) use:
Dim array_unsorted As Variant 'must be variant!
array_unsorted = ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value '2-dimensional array
you can access the array with
Debug.Print array_unsorted(row, column) 'yes it has only 1 column but it is still there
Debug.Print array_unsorted(1, 1) 'first value
Debug.Print array_unsorted(2, 1) 'second value
or transpose it to make it 1-dimensional
array_unsorted = WorksheetFunction.Transpose(ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value) '1-dimensional
and you can access the array with
Debug.Print array_unsorted(i) 'this is 1-dimensional
Debug.Print array_unsorted(1) 'first value
Debug.Print array_unsorted(2) 'second value
Note that the transpose function has a limit of 65,536 rows. If you exceed them the rest will be truncated silently.
I recommend to avoid ActiveWorksheet
(unless you write an add-in or the code is used for multiple worksheets). Use ThisWorkbook.Worksheets("NameOfSheet")
to reference the worksheet by its name, which is more save and Excel won't run into errors.
To easily load a range into an array (without a loop) use:
Dim array_unsorted As Variant 'must be variant!
array_unsorted = ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value '2-dimensional array
you can access the array with
Debug.Print array_unsorted(row, column) 'yes it has only 1 column but it is still there
Debug.Print array_unsorted(1, 1) 'first value
Debug.Print array_unsorted(2, 1) 'second value
or transpose it to make it 1-dimensional
array_unsorted = WorksheetFunction.Transpose(ThisWorkbook.Worksheets("NameOfSheet").Range("B6:B183").Value) '1-dimensional
and you can access the array with
Debug.Print array_unsorted(i) 'this is 1-dimensional
Debug.Print array_unsorted(1) 'first value
Debug.Print array_unsorted(2) 'second value
Note that the transpose function has a limit of 65,536 rows. If you exceed them the rest will be truncated silently.
I recommend to avoid ActiveWorksheet
(unless you write an add-in or the code is used for multiple worksheets). Use ThisWorkbook.Worksheets("NameOfSheet")
to reference the worksheet by its name, which is more save and Excel won't run into errors.
edited Nov 21 '18 at 9:31
answered Nov 21 '18 at 9:16
PᴇʜPᴇʜ
22.2k42750
22.2k42750
1
Variant for 2-dimensional array worked, thanks. I suggest that will be enough for this project.
– Lomil
Nov 21 '18 at 9:30
add a comment |
1
Variant for 2-dimensional array worked, thanks. I suggest that will be enough for this project.
– Lomil
Nov 21 '18 at 9:30
1
1
Variant for 2-dimensional array worked, thanks. I suggest that will be enough for this project.
– Lomil
Nov 21 '18 at 9:30
Variant for 2-dimensional array worked, thanks. I suggest that will be enough for this project.
– Lomil
Nov 21 '18 at 9:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408372%2fim-trying-to-create-array-with-value-from-activesheet-vba%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You have a typo in
ActiveWorsheet
(missingk
) • But you can just doarray_unsorted = ActiveWorksheet.Range("B6:B183").Value
to load the range into an array (2-dimensional). If you want it 1-dimensional transpose the range:array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
– Pᴇʜ
Nov 21 '18 at 8:59
I'm trying to write
Dim array_unsorted() As String ReDim array_unsorted(0 To 200) array_unsorted = ActiveWorksheet.Range("B6:B183").Value
but it still return empty array without data.array_unsorted = WorksheetFunction.Transpose(ActiveWorksheet.Range("B6:B183").Value)
return the same.– Lomil
Nov 21 '18 at 9:12
I posted it as an answer to make it more clear.
– Pᴇʜ
Nov 21 '18 at 9:27