Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello All,
In my call to the following subroutine, the For Loop is supposed to iterate 51 times. It does this fine when I run it with "step into," but does not work when executed any other way. Sub HideEmptyColumns(wks As Worksheet, lastcolumn As Long, firstrow As Long) 'Hides all empty columns in the wks worksheet between columns 1 and lastcolumn 'if the last non-empty row is firstrow Dim col As Long Dim LastRow As Long ResetUsedRange wks For col = 1 To lastcolumn LastRow = (wks.Cells(Rows.Count, col).End(xlUp).row) If LastRow = firstrow Then Columns(col).Hidden = True End If Next col End Sub Might Excel not be giving the code enough time to execute? If so, how do I give the bit of code more time? I appreciate any help. Thanks, Sisilla |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Sisilla
Working for me correct if the activesheet is the wks sheet Change Columns(col).Hidden = True to wks.Columns(col).Hidden = True Do you see a error ? If you not use ResetUsedRange wks -- Regards Ron de Bruin http://www.rondebruin.nl "Sisilla" wrote in message ups.com... Hello All, In my call to the following subroutine, the For Loop is supposed to iterate 51 times. It does this fine when I run it with "step into," but does not work when executed any other way. Sub HideEmptyColumns(wks As Worksheet, lastcolumn As Long, firstrow As Long) 'Hides all empty columns in the wks worksheet between columns 1 and lastcolumn 'if the last non-empty row is firstrow Dim col As Long Dim LastRow As Long ResetUsedRange wks For col = 1 To lastcolumn LastRow = (wks.Cells(Rows.Count, col).End(xlUp).row) If LastRow = firstrow Then Columns(col).Hidden = True End If Next col End Sub Might Excel not be giving the code enough time to execute? If so, how do I give the bit of code more time? I appreciate any help. Thanks, Sisilla |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you, Ron. I'll test out your solution. I turned off
ScreenUpdating before the loop and turned it back on again after the loop, and it seems to be working. I greatly appreciate your help. Sisilla Ron de Bruin wrote: Hi Sisilla Working for me correct if the activesheet is the wks sheet Change Columns(col).Hidden = True to wks.Columns(col).Hidden = True Do you see a error ? If you not use ResetUsedRange wks -- Regards Ron de Bruin http://www.rondebruin.nl "Sisilla" wrote in message ups.com... Hello All, In my call to the following subroutine, the For Loop is supposed to iterate 51 times. It does this fine when I run it with "step into," but does not work when executed any other way. Sub HideEmptyColumns(wks As Worksheet, lastcolumn As Long, firstrow As Long) 'Hides all empty columns in the wks worksheet between columns 1 and lastcolumn 'if the last non-empty row is firstrow Dim col As Long Dim LastRow As Long ResetUsedRange wks For col = 1 To lastcolumn LastRow = (wks.Cells(Rows.Count, col).End(xlUp).row) If LastRow = firstrow Then Columns(col).Hidden = True End If Next col End Sub Might Excel not be giving the code enough time to execute? If so, how do I give the bit of code more time? I appreciate any help. Thanks, Sisilla |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro code to remove a macro after it executes | Excel Programming | |||
Can I slow the rate that VB executes individual orders? | Excel Programming | |||
SAveAs executes combobox code | Excel Programming | |||
excel executes only a part of a macro | Excel Programming | |||
Count # of Times Sub Executes | Excel Programming |