Issue with variable type?

Cummins

Board Regular
Joined
Jul 26, 2011
Messages
58
When this step is reached, "Data1 = Str(F1.Cells(x, 1))" I get the error "Type mismatch." It only happens when the input data changes from a string of numbers stored as text "6666666" to "wafer test 112608"
Is there a better declaration for Data1?



Public Ary1() As String
Dim Data1 As String
Public NumBtchs As Integer
Public ExtractMethod


Sub PullAllBatchData()


ExtractMethod = 1

Workbook_Open

End Sub


Public Sub PullManualBatchData()

'Need to define Ary1 as a public array as it will be used in another Module


'ExtractMethod will define in other modules how to handle the data extraction
ExtractMethod = 2
'Defines F1 as the active sheet and activates it.
Set F1 = ActiveWorkbook.ActiveSheet
F1.Activate

'Need to define what the last row in Column A
lastrow1 = F1.Range("A" & Rows.Count).End(xlUp).Row

ReDim Ary1(lastrow1, 1)

NumBtchs = 0
For x = 1 To lastrow1
Data1 = Str(F1.Cells(x, 1))
F1.Cells(x, 1).Activate 'Cell needs to be activated for next line
If IsEmpty(ActiveCell.Value) Then Data1 = ""
If Data1 <> "" Then NumBtchs = NumBtchs + 1: Ary1(NumBtchs, 1) = Data1
Next

Workbook_Open



End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try changing it to:

Data1 = Str(F1.Cells(x, 1).Value)

Otherwise you're referring to a cell object (range) and not a string value.
 
Upvote 0
Just on a side note, if the variable type changes then you may want to declare it as a variant.

Hope this helps.

AMAS
 
Upvote 0
Thanks guys. You caught me just before I jumped off my stool. The Excel version I was using is 2003...but the company is in the process of moving to 2010.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,973
Members
448,933
Latest member
Bluedbw

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