0
votes

I have a created a sub to check a value of a column and clear contents of a particular range. But when selecting the value, I continuously get type mismatch error. I have tried the following four methods too. The sheet is refreshed from a sql server source and the datatype of it is string. I changed the data in the source to be a int but of now use. Any help will be highly appreciated.

Sub abc()
    Dim var1 As String
    **var1 = Sheets(Sheet1).Cells(1, "A").Value
    var1 = Sheets(Sheet1).Cells(1, "A").Text
    var1 = Sheets(Sheet1).Range("A1").Value
    var1 = Sheets(Sheet1).Range("A1").Text**
End Sub
2
Sheets("Sheet1") assuming Sheet1 is its name. - SJR
yes.. you are right. Any other thing that I'm missing in the code? - user4595869
According to here stackoverflow.com/questions/17359835/… you should probably be using Value2 instead of Value or Text (and definitely not the latter). I have to confess to never using it but perhaps should mend my ways. - SJR
tried that too. still the same error. It's really very strange! - user4595869
Not sure what is the problem - which line errors?. You've posted four versions of basically the same line but your question refers to other things so you need to post all the code. - SJR

2 Answers

0
votes

Try changing var1 type from string to Range or variant.

0
votes

Thanks for all the comments provided. Fixed the issue. Added quotes around Changed var1 = Sheets(Sheet1).Range("A1").Value