OxfordCurmudgeon
New Member
- Joined
- Oct 24, 2023
- Messages
- 14
- Office Version
- 2010
- 2003 or older
- Platform
- Windows
I'm baffled. This code works:
Set DataSourceSheet = ActiveSheet
With DataSourceSheet
DataHoldRows = .UsedRange.Rows.Count
DataHoldCols = .UsedRange.Columns.Count
DataHold = .Range(.Cells(1, 1), .Cells(DataHoldRows, DataHoldCols))
End With
This code does not:
With ActiveSheet
DataHoldRows = .UsedRange.Rows.Count
DataHoldCols = .UsedRange.Columns.Count
DataHold = .Range(.Cells(1, 1), .Cells(DataHoldRows, DataHoldCols))
End With
I get "Run-time error '13': Type mismatch" on the DataHold = line. The first two assignments work correctly either way. I've used the Watch window to verify that ActiveSheet is pointing where I thought it would.
The code to declare the variables was unchanged:
Dim DataSourceSheet As Worksheet
Dim DataHold() As Variant
Dim DataHoldRows As Integer
Dim DataHoldCols As Integer
I'm trying to gain some mastery of Excel VBA and would like to understand why the code is failing.
Set DataSourceSheet = ActiveSheet
With DataSourceSheet
DataHoldRows = .UsedRange.Rows.Count
DataHoldCols = .UsedRange.Columns.Count
DataHold = .Range(.Cells(1, 1), .Cells(DataHoldRows, DataHoldCols))
End With
This code does not:
With ActiveSheet
DataHoldRows = .UsedRange.Rows.Count
DataHoldCols = .UsedRange.Columns.Count
DataHold = .Range(.Cells(1, 1), .Cells(DataHoldRows, DataHoldCols))
End With
I get "Run-time error '13': Type mismatch" on the DataHold = line. The first two assignments work correctly either way. I've used the Watch window to verify that ActiveSheet is pointing where I thought it would.
The code to declare the variables was unchanged:
Dim DataSourceSheet As Worksheet
Dim DataHold() As Variant
Dim DataHoldRows As Integer
Dim DataHoldCols As Integer
I'm trying to gain some mastery of Excel VBA and would like to understand why the code is failing.