how to insert a row before pasting an array

rbysetty

New Member
Joined
Jul 3, 2012
Messages
22
I currently have an array which I populate and paste in a sheet named "T1" using a macro. my current macro uses the rowcount function to determine the used rows and pastes the array from the next available row. The problem i am having is that when I paste this array multiple times, the arrays need to be spaced by a row so that i can differentiate different submissions. this is what i have so far, and i was hoping someone could help me with this

Sub CopyData()

Dim Truearray() As String
Dim cell As Excel.Range
Dim RowCount1 As Integer
Dim i As Integer
Dim ii As Integer
Dim col As Range
Dim col2 As Range
i = 0
ii = 2

RowCount1 = DHRSheet.UsedRange.Rows.Count
Set col = DHRSheet.Range("I1:I" & RowCount1)

For Each cell In col

If cell.Value = "True" Then

Dim ValueCell As Range
Set ValueCell = Cells(cell.Row, 3)
ReDim Preserve Truearray(i)
Truearray(i) = ValueCell.Value

Dim siblingCell As Range
Set siblingCell = Cells(cell.Row, 2)
Dim Siblingarray() As String

ReDim Preserve Siblingarray(i)
Siblingarray(i) = DHRSheet.Name & "$" & siblingCell.Value

i = i + 1

End If

Next

Dim RowCount2 As Integer

RowCount2 = DataSheet.UsedRange.Rows.Count + 1

For ii = 2 To UBound(Truearray)
DataSheet.Cells(RowCount2 + ii, 2).Value = Truearray(ii)
Next

For ii = 2 To UBound(Siblingarray)
DataSheet.Cells(RowCount2 + ii, 1).Value = Siblingarray(ii)
Next

DataSheet.Columns("A:B").AutoFit

MsgBox ("Data entered has been successfully validated & logged")


End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try changing this line:
Rich (BB code):
RowCount2 = DataSheet.UsedRange.Rows.Count + 1
to
Rich (BB code):
RowCount2 = DataSheet.UsedRange.Rows.Count + 2
 
Upvote 0
Sorry but that is puzzling to say the least. Can you step through the code especially the RowCount2 using F8 (Step through the code).
 
Upvote 0

Forum statistics

Threads
1,215,606
Messages
6,125,805
Members
449,262
Latest member
hideto94

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