I`m trying to create array with value from activesheet (VBA)












2















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




In Locals










share|improve this question




















  • 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













  • 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
















2















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




In Locals










share|improve this question




















  • 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













  • 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














2












2








2








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




In Locals










share|improve this question
















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




In Locals







excel vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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 posted it as an answer to make it more clear.

    – Pᴇʜ
    Nov 21 '18 at 9:27














  • 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













  • 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








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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer





















  • 1





    Variant for 2-dimensional array worked, thanks. I suggest that will be enough for this project.

    – Lomil
    Nov 21 '18 at 9:30













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
});


}
});














draft saved

draft discarded


















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









1














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.






share|improve this answer





















  • 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














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.






share|improve this answer





















  • 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








1







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

Npm cannot find a required file even through it is in the searched directory

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith