Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 45
Default VB syntax problem with referencing another tab

Hi. The following macro works fine if I run it while the tab in question is
open. If I try to run it with another tab open, I get a 400 error. I'm pretty
sure it's just a problem with the way I'm referencing the tab. Any ideas on
how I could make this work?


Sub Formatierung_Einverkauf()

Set sh1 = Sheets("Einverkauf")

z = 4
Do Until sh1.Cells(z, 1).Value = ""
If sh1.Cells(z, 1).Value < sh1.Cells(z + 1, 1).Value Then
sh1.Rows(z).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
z = z + 1
Else
z = z + 1
End If

Loop

End Sub

Thanks a lot
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 834
Default VB syntax problem with referencing another tab

This works fine for me

Sub Formatierung_Einverkauf()
Dim z As Long
z = 4
With Sheets("Einverkauf")
Do Until .Cells(z, 1).Value = ""
If .Cells(z, 1).Value < .Cells(z + 1, 1).Value Then
With .Rows(z).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End If
z = z + 1
Loop
End With
End Sub


--

HTH

Bob

"Wombat" wrote in message
...
Hi. The following macro works fine if I run it while the tab in question
is
open. If I try to run it with another tab open, I get a 400 error. I'm
pretty
sure it's just a problem with the way I'm referencing the tab. Any ideas
on
how I could make this work?


Sub Formatierung_Einverkauf()

Set sh1 = Sheets("Einverkauf")

z = 4
Do Until sh1.Cells(z, 1).Value = ""
If sh1.Cells(z, 1).Value < sh1.Cells(z + 1, 1).Value Then
sh1.Rows(z).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
z = z + 1
Else
z = z + 1
End If

Loop

End Sub

Thanks a lot



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default VB syntax problem with referencing another tab

Hi,

There is vertually never any need to select cells to perform operations on
them and this was the issue with this code, you tried to select on an
inactive sheet. Do it this way

Sub Formatierung_Einverkauf()
Set sh1 = Sheets("Einverkauf")
Z = 4
Do Until sh1.Cells(Z, 1).Value = ""
If sh1.Cells(Z, 1).Value < sh1.Cells(Z + 1, 1).Value Then
With sh1.Rows(Z).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Z = Z + 1
Else
Z = Z + 1
End If
Loop
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Wombat" wrote:

Hi. The following macro works fine if I run it while the tab in question is
open. If I try to run it with another tab open, I get a 400 error. I'm pretty
sure it's just a problem with the way I'm referencing the tab. Any ideas on
how I could make this work?


Sub Formatierung_Einverkauf()

Set sh1 = Sheets("Einverkauf")

z = 4
Do Until sh1.Cells(z, 1).Value = ""
If sh1.Cells(z, 1).Value < sh1.Cells(z + 1, 1).Value Then
sh1.Rows(z).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
z = z + 1
Else
z = z + 1
End If

Loop

End Sub

Thanks a lot

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
Problem with Syntax? MurrayBarn Excel Worksheet Functions 8 June 12th 09 01:45 PM
What is the syntax for referencing another sheet with 'lookup' ihenderson Excel Worksheet Functions 3 July 31st 06 12:05 PM
SendKeys syntax problem VBAvirgin New Users to Excel 2 January 4th 06 04:42 PM
Syntax for referencing totals of grouped data in a pivottable mbpcon Excel Worksheet Functions 1 October 23rd 05 05:24 PM
Syntax problem Alex H Excel Worksheet Functions 1 July 2nd 05 08:23 AM


All times are GMT +1. The time now is 07:16 PM.

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

About Us

"It's about Microsoft Excel"