ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   mismatch error in returning concatonation of numbers and characters (https://www.excelbanter.com/excel-programming/310971-mismatch-error-returning-concatonation-numbers-characters.html)

skrimpy

mismatch error in returning concatonation of numbers and characters
 

I have two cells in a row. By the nature of formulas within the cell
they will either have a number, or the text "n/a". I want to write
loop that will look into the second cell to see if "n/a" is present.
If it is "n/a" I want what is contained in the first cell to b
returned to a text box (t1), which could be a number or could be "n/a"
If the second cell contains a number, the first cell will also contai
a number, and I want both numbers returned to the text box (t1) with
comma between them. ie "15 , 16" or "15 , 15" etc..... I then wan
the loop to continue through 13 different sets of cells with on
corresponding text box. Here is what I have for the first set o
cells.

'Declare Variables
Dim Counter As Integer
Dim a As Byte
Dim b As Byte
Dim c As String
'Activate Worksheet and define range
Worksheets("Sheet1").Activate
'Initialize Variables
Counter = 0
a = 9
b = 3
c = Cells(b, a)
'Return values from cells
Do
If c = "n/a" Then
t1 = ActiveSheet.Cells(b, a - 1)
Else: t1 = ActiveSheet.Cells(b, a - 1) + "," + ActiveSheet.Cells(b
a)
End If
Counter = Counter + 1
Loop Until Counter = 1

I keep getting a type mismatch error. I think this is because I hav
numbers being returned :mad: in concatonation with a string characte
(the comma). Is there a way to convert those numbers to a string s
that I will not have this error? Or am I wrong about why I'm gettin
the error? Thanks to anyone that can help me

--
skrimp
-----------------------------------------------------------------------
skrimpy's Profile: http://www.excelforum.com/member.php...fo&userid=1463
View this thread: http://www.excelforum.com/showthread.php?threadid=26265


Don Lloyd

mismatch error in returning concatonation of numbers and characters
 
Hi,

try using & instead of +

regards,
Don

"skrimpy" wrote in message
...

I have two cells in a row. By the nature of formulas within the cells
they will either have a number, or the text "n/a". I want to write a
loop that will look into the second cell to see if "n/a" is present.
If it is "n/a" I want what is contained in the first cell to be
returned to a text box (t1), which could be a number or could be "n/a".
If the second cell contains a number, the first cell will also contain
a number, and I want both numbers returned to the text box (t1) with a
comma between them. ie "15 , 16" or "15 , 15" etc..... I then want
the loop to continue through 13 different sets of cells with one
corresponding text box. Here is what I have for the first set of
cells.

'Declare Variables
Dim Counter As Integer
Dim a As Byte
Dim b As Byte
Dim c As String
'Activate Worksheet and define range
Worksheets("Sheet1").Activate
'Initialize Variables
Counter = 0
a = 9
b = 3
c = Cells(b, a)
'Return values from cells
Do
If c = "n/a" Then
t1 = ActiveSheet.Cells(b, a - 1)
Else: t1 = ActiveSheet.Cells(b, a - 1) + "," + ActiveSheet.Cells(b,
a)
End If
Counter = Counter + 1
Loop Until Counter = 1

I keep getting a type mismatch error. I think this is because I have
numbers being returned :mad: in concatonation with a string character
(the comma). Is there a way to convert those numbers to a string so
that I will not have this error? Or am I wrong about why I'm getting
the error? Thanks to anyone that can help me.


--
skrimpy
------------------------------------------------------------------------
skrimpy's Profile:
http://www.excelforum.com/member.php...o&userid=14634
View this thread: http://www.excelforum.com/showthread...hreadid=262653





All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com