Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 354
Default data type mismatch error

Below is my macro to draw bar chart Pattern DarkUpward Diagonal if
Rng2.value in data sheet 3. Today, there are no data and I have this error
'data type mismatch'

How can I fix this

Thanks In advance
Daniel



Dim Cnt2 As Integer
Dim S As Integer
r = Range("B1").CurrentRegion.Rows.Count


For Each Rng2 In Range(.Cells(2, 6), .Cells(r, 6))
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt2)

Pts.HasDataLabel = True


S = Now - Rng2.Value

Pts.DataLabel.Font.Size = 7

Pts.DataLabel.Text = S


If Now - Rng2.Value 3 Then

Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal


End If
Cnt2 = Cnt2 + 1
Next Rng2


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default data type mismatch error

Use a qualification statement like: If Rng2.Value 0 Then 'do something

I would try to pick a point in my code where the test would have to be done
only once, instead of testing each iteration.

"Daniel" wrote:

Below is my macro to draw bar chart Pattern DarkUpward Diagonal if
Rng2.value in data sheet 3. Today, there are no data and I have this error
'data type mismatch'

How can I fix this

Thanks In advance
Daniel



Dim Cnt2 As Integer
Dim S As Integer
r = Range("B1").CurrentRegion.Rows.Count


For Each Rng2 In Range(.Cells(2, 6), .Cells(r, 6))
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt2)

Pts.HasDataLabel = True


S = Now - Rng2.Value

Pts.DataLabel.Font.Size = 7

Pts.DataLabel.Text = S


If Now - Rng2.Value 3 Then

Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal


End If
Cnt2 = Cnt2 + 1
Next Rng2


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default data type mismatch error

The way your code is structured, you will have to include the test within the
For...Next statement as shown below:

Dim Cnt2 As Integer
Dim S As Integer
r = Range("B1").CurrentRegion.Rows.Count
For Each Rng2 In Range(.Cells(2, 6), .Cells(r, 6))
If Rng2 < "" Then '<<<Test for value in Rng2
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt2)
Pts.HasDataLabel = True
S = Now - Rng2.Value
Pts.DataLabel.Font.Size = 7
Pts.DataLabel.Text = S
If Now - Rng2.Value 3 Then
Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal
End If
Cnt2 = Cnt2 + 1
End If
Next Rng2


"Daniel" wrote:

Below is my macro to draw bar chart Pattern DarkUpward Diagonal if
Rng2.value in data sheet 3. Today, there are no data and I have this error
'data type mismatch'

How can I fix this

Thanks In advance
Daniel



Dim Cnt2 As Integer
Dim S As Integer
r = Range("B1").CurrentRegion.Rows.Count


For Each Rng2 In Range(.Cells(2, 6), .Cells(r, 6))
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt2)

Pts.HasDataLabel = True


S = Now - Rng2.Value

Pts.DataLabel.Font.Size = 7

Pts.DataLabel.Text = S


If Now - Rng2.Value 3 Then

Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal


End If
Cnt2 = Cnt2 + 1
Next Rng2


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 354
Default data type mismatch error

Thanks JLWhiz
I will include this test code in my macro.
I check and it works fine
Thanks again for taking time with valuable advice.
Daniel

"JLGWhiz" wrote:

The way your code is structured, you will have to include the test within the
For...Next statement as shown below:

Dim Cnt2 As Integer
Dim S As Integer
r = Range("B1").CurrentRegion.Rows.Count
For Each Rng2 In Range(.Cells(2, 6), .Cells(r, 6))
If Rng2 < "" Then '<<<Test for value in Rng2
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt2)
Pts.HasDataLabel = True
S = Now - Rng2.Value
Pts.DataLabel.Font.Size = 7
Pts.DataLabel.Text = S
If Now - Rng2.Value 3 Then
Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal
End If
Cnt2 = Cnt2 + 1
End If
Next Rng2


"Daniel" wrote:

Below is my macro to draw bar chart Pattern DarkUpward Diagonal if
Rng2.value in data sheet 3. Today, there are no data and I have this error
'data type mismatch'

How can I fix this

Thanks In advance
Daniel



Dim Cnt2 As Integer
Dim S As Integer
r = Range("B1").CurrentRegion.Rows.Count


For Each Rng2 In Range(.Cells(2, 6), .Cells(r, 6))
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt2)

Pts.HasDataLabel = True


S = Now - Rng2.Value

Pts.DataLabel.Font.Size = 7

Pts.DataLabel.Text = S


If Now - Rng2.Value 3 Then

Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal


End If
Cnt2 = Cnt2 + 1
Next Rng2


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default data type mismatch error

One other thing you might try is to use the Format function to get your data
elements to the same data type. Assuming that Rng2 is a date from the way it
is used in the test If Now - Rng2.Value... , you could do something like this:

If Format(Now, "d") - Format(Rng2.Value, "d") 3 Then
Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal
End If

The minus sign yields a numeric result so it should not give you the type
mismatch.
You can try both methods and see which gives the best results.

"Daniel" wrote:

Thanks JLWhiz
I will include this test code in my macro.
I check and it works fine
Thanks again for taking time with valuable advice.
Daniel

"JLGWhiz" wrote:

The way your code is structured, you will have to include the test within the
For...Next statement as shown below:

Dim Cnt2 As Integer
Dim S As Integer
r = Range("B1").CurrentRegion.Rows.Count
For Each Rng2 In Range(.Cells(2, 6), .Cells(r, 6))
If Rng2 < "" Then '<<<Test for value in Rng2
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt2)
Pts.HasDataLabel = True
S = Now - Rng2.Value
Pts.DataLabel.Font.Size = 7
Pts.DataLabel.Text = S
If Now - Rng2.Value 3 Then
Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal
End If
Cnt2 = Cnt2 + 1
End If
Next Rng2


"Daniel" wrote:

Below is my macro to draw bar chart Pattern DarkUpward Diagonal if
Rng2.value in data sheet 3. Today, there are no data and I have this error
'data type mismatch'

How can I fix this

Thanks In advance
Daniel



Dim Cnt2 As Integer
Dim S As Integer
r = Range("B1").CurrentRegion.Rows.Count


For Each Rng2 In Range(.Cells(2, 6), .Cells(r, 6))
Set Pts = ActiveChart.SeriesCollection(1).Points(Cnt2)

Pts.HasDataLabel = True


S = Now - Rng2.Value

Pts.DataLabel.Font.Size = 7

Pts.DataLabel.Text = S


If Now - Rng2.Value 3 Then

Pts.Fill.Patterned Pattern:=msoPatternDarkUpwardDiagonal


End If
Cnt2 = Cnt2 + 1
Next Rng2


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Type Mismatch Error when getting data from another workbook Tony Zappal Excel Programming 2 January 12th 05 10:29 PM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM
Copying data to another worksheet gives "Type Mismatch" error TB[_3_] Excel Programming 6 July 28th 03 12:44 PM


All times are GMT +1. The time now is 05:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"