Dump array onto worksheet

krice1974

Active Member
Joined
Jul 3, 2008
Messages
422
Hi all. I searched help and I'm sure this has been answered hundreds of times here but I can't seem to make the given solutions apply. Anyway.

I'd like to "dump" an array onto a worksheet. It's called MyArray, it's varying in length, 7 "columns" wide, and I know the uppermost left cell I'd like to dump to.

Many thanks in advance...

Kevin
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Do you mean copy and paste the range MyArray to a specific location? Manually or via VBA?

Why not select the range, copy to the clipboard, click on your target cell and then paste?

Is there more to your request than that?
 
Upvote 0
yes, much... I want vba to do it automatically, and without the worksheets being active, every day at a set time...
 
Upvote 0
but that is the meat of it... i want to copy a range but I have to refine the range, so it's best to load an array (i think)
 
Upvote 0
Code to copy and paste is easy.

<code>
Sub CopyPaste()
Application.Goto Reference:="MyArray"
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub
</code>

But I doubt this can be done in a closed workbook. You can run this when the wb is open. And even have it run automatically when the wb opens, but I don't think it will simply run in the background when the wb is closed
 
Upvote 0
Thanks. That would work nicely if I was able to run it the way you mentioned. I'll copy that for future use though but I do need something array- based I think...
 
Upvote 0
Hi. GTO, I'm really struggling getting that started. I pasted this query earlier but it fell off the board I guess. I'll paste my code below. I know some is rough, I'm working through it now but hung up. In a nutshell I want to loop through a worksheet that contains a web query. The query is rough in format (non- continuous) but there are continuous sections within it that i want to copy. I want to get to the range (see in code, finding the word "company"), copy it into an array with a loop, ending the loop on a blank cell, which resumes the outer loop that continues down looking for the word "company." Upon finding it again, the inner loop runs again, APPENDING/ ADDING TO the original data in the array. To append to the array, I think I should use worksheetfunction.count?? but how on just one "column" of the array?? *sigh.

I really hope this makes sense. I think I'd go a long way if I can get this to work and get the concepts behind it but I keep getting turned in other directions. Here's the code...

Dim DataArray() As Variant 'Main data array
Dim ArrayLength As Integer 'Array length
Dim UGQFinalRow As Long 'Final row of worksheet BriefingAnalystUpsDwnsQuery
Dim UGQFinalRowFixed As Long 'Final row of worksheet BriefingAnalystUpsDwnsQuery
Dim UGQNewRow As Long 'Final row of worksheet BriefingAnalystUpsDwnsQuery
Dim UGNewRow As Long 'Final row of worksheet BriefingAnalystUpsDwns
Dim UGQ As Worksheet 'Worksheet abbreviated reference BriefingAnalystUpsDwnsQuery
Dim UG As Worksheet 'Worksheet abbreviated reference BriefingAnalystUpsDwns
Dim RatingType As String 'The rating type/ category
Dim DataReigon As Range 'The final, semi- revised block of data that appears at the bottom of the sheet.

'Abbreviate worksheet name.
Set UGQ = Worksheets("BriefingAnalystUpsDwnsQuery")
Set UG = Worksheets("BriefingAnalystUpsDwns")

'Get final row of worksheet.

UGQFinalRow = UGQ.Cells(Rows.count, 1).End(xlUp).Row
UGQFinalRowFixed = UGQ.Cells(Rows.count, 1).End(xlUp).Row

'Initialize main outer loop.
Dim i As Integer 'Counter variable for main/ outer loop
Dim j As Integer 'Counter variable for inner do while loop
For i = 1 To UGQFinalRow 'Outer loop that loops through the entire worksheet looking for the word "company."
'Once it finds "company", it checks for "upgrades, downgrades, and coverage initiated."
If UGQ.Cells(i, 1).Value = "Company" Then
Select Case UGQ.Cells((i - 3), 1).Value
Case "Upgrades"
RatingType = "Upgrades"
Case "Downgrades"
RatingType = "Downgrades"
Case "Coverage Initiated"
RatingType = "Initiated"
Case "Coverage Reit/Price Tgt Changed*"
RatingType = "TargetChange"
End Select

j = 1

Do While UGQ.Cells(i + j, 1).Value <> ""
j = j + 1
Loop

ArrayLength = WorksheetFunction.count(DataArray)
ReDim Preserve DataArray(ArrayLength)

DataArray(i + j, 1) = UGQ.Cells(i + j, 2).Value 'Symbol load into array
DataArray(i + j, 2) = UGQ.Cells(i + j, 1).Value 'Company load into array
DataArray(i + j, 3) = RatingType 'Alert name load into array
DataArray(i + j, 4) = UGQ.Cells(i + j, 3).Value 'Firm load into array
DataArray(i + j, 5) = UGQ.Cells(i + j, 4).Value 'Rating change load into array
DataArray(i + j, 6) = UGQ.Cells(i + j, 5).Value 'Price target load into array

j = j - 2

End If

Next i
 
Upvote 0
If the last post was overwhelming, here's an hour's more work and hopefully something easier to digest:

Dim DataArray() As Variant 'Main data array
Dim ArrayLength As Integer 'Array length
Dim UGQFinalRow As Long 'Final row of worksheet BriefingAnalystUpsDwnsQuery
Dim UGQFinalRowFixed As Long 'Final row of worksheet BriefingAnalystUpsDwnsQuery
Dim UGQNewRow As Long 'Final row of worksheet BriefingAnalystUpsDwnsQuery
Dim UGNewRow As Long 'Final row of worksheet BriefingAnalystUpsDwns
Dim UGQ As Worksheet 'Worksheet abbreviated reference BriefingAnalystUpsDwnsQuery
Dim DataReigon As Range 'The final, semi- revised block of data that appears at the bottom of the sheet.

'Abbreviate worksheet name.
Set UGQ = Worksheets("BriefingAnalystUpsDwnsQuery")

There is an outer for next loop that this section below is nested in. This inner part runs when the outer loop finds continuous data. I want to add that data to DataArray, resume the loop, and append the next continuous range to it when encountered. The variable "i" is the outer counter, this also gives the cell address for the data being copied to the array below.

'Get length of current range of data.
j = 1

Do While UGQ.Cells(i + j, 1).Value <> ""
j = j + 1
Loop

'Loop through current range, loading array.

Dim k As Integer
For k = UBound(DataArray) + 1 To UBound(DataArray) + j

DataArray(k, 1) = UGQ.Cells(i + j, 2).Value 'Symbol load into array
DataArray(k, 2) = UGQ.Cells(i + j, 1).Value 'Company load into array
DataArray(k, 3) = RatingType 'Alert name load into array
DataArray(k, 4) = UGQ.Cells(i + j, 3).Value 'Firm load into array
DataArray(k, 5) = UGQ.Cells(i + j, 4).Value 'Rating change load into array
DataArray(k, 6) = UGQ.Cells(i + j, 5).Value 'Price target load into array

Next k

I'm truly stuck here, thanks for patience with a newbie.
 
Upvote 0
Greetings Krice,

I am a bit busy, but will try and read thru. Your notation is a bit hard for me to follow. Not a negative comment, just explaining the delay.

Mark

Edit: I lacked clarity.

By notation I mean naming convention, not the rem's - these are nice :)
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,311
Members
449,080
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top