B
blobb
Hi. I am new to VBA and am attempting to copy multiple ranges found in
worksheet "SubjID" to a Summary Data Sheet. I found the following code
online (I included the form frmSubjIDPrompt - simply goes to the SubjID
worksheet that the user inputs). I keep getting the error "Type Mismatch" at
the set destrange command. I am unable to figure out why that would be
happening. Could someone help? Thank you!
Sub CopyMultiAreaValues()
Dim SubjID As Integer
Dim destrange As Range
Dim smallrng As Range
'prompt for subject id number and go to that worksheet
frmSubjIDPrompt.Show
'select range of multiple areas to copy to SummaryData worksheet
For Each smallrng In ActiveSheet. _
Range("a4,d6:AC6,D10:J10,L10:R10,D11:J11,L11:R11").Areas
With smallrng
Set destrange = Sheets("SummaryData").Range("D" & _
lastrow(Sheets("SummaryData")) + 1).Resize( _
.Rows.Count, .Columns.Count)
End With
destrange.Value = smallrng.Value
Next smallrng
End Sub
Function lastrow(sh As Workbook)
On Error Resume Next
lastrow = sh.Cells.Find(What:="*", _
After:=sh.Range("D1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
worksheet "SubjID" to a Summary Data Sheet. I found the following code
online (I included the form frmSubjIDPrompt - simply goes to the SubjID
worksheet that the user inputs). I keep getting the error "Type Mismatch" at
the set destrange command. I am unable to figure out why that would be
happening. Could someone help? Thank you!
Sub CopyMultiAreaValues()
Dim SubjID As Integer
Dim destrange As Range
Dim smallrng As Range
'prompt for subject id number and go to that worksheet
frmSubjIDPrompt.Show
'select range of multiple areas to copy to SummaryData worksheet
For Each smallrng In ActiveSheet. _
Range("a4,d6:AC6,D10:J10,L10:R10,D11:J11,L11:R11").Areas
With smallrng
Set destrange = Sheets("SummaryData").Range("D" & _
lastrow(Sheets("SummaryData")) + 1).Resize( _
.Rows.Count, .Columns.Count)
End With
destrange.Value = smallrng.Value
Next smallrng
End Sub
Function lastrow(sh As Workbook)
On Error Resume Next
lastrow = sh.Cells.Find(What:="*", _
After:=sh.Range("D1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function