LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default IF statement to activate worksheet & select Range

Hi All,

I have a Workbook (don't we all if we're looking for help here), with a
worksheet at the end that I have several command buttons on. The first
command button will insert a new worksheet that uses a variable as part of
the naming (i.e. Rename to "Formula Sheet #" & <variable) and inserts the
sheet before the "command button sheet." It is working successfully as far
as inserting and naming goes. I have the varible declared in the Public area
so I can use it for the rest of the buttons.

The rest of the buttons have a macro attached to them with an IF statement.
They are supposed to activate Formula Sheet #<variable and using the IF at
this point select a range based on the criteria. The code for the whole
thing is as follows

Worksheets("Formula Sheet #" & FormSheet).Activate
If LeftRight / 2 = FormatNumber(LeftRight / 2, 0) Then
FirstRow = Cells(Rows.Count, "A").End(xlUp).Offset(2, 0).Row
FirstCol = Cells(FirstRow, Columns.Count).End(xlToLeft).Column
Range(Cells(FirstRow, FirstCol), Cells(FirstRow + 6, FirstCol + 2)).Select
Else
FirstRow = Cells(FirstRow, FirstCol).End(xlUp).Offset(2, 0).Row
FirstCol = Cells(FirstRow, Columns.Count).End(xlToLeft).Offset(0,
4).Column
Range(Cells(FirstRow, FirstCol), Cells(FirstRow + 6, FirstCol + 2)).Select
End If

The IF portion determines where the range will be selected based on whether
or not LeftRight is even/odd. Basically the "odd" time any of the "range
selection buttons" are used the group of cells to the far left will be
selected and merged where an even LeftRight will select the range a couple of
cells to the right of the previous range and merge it. The problem I am
having is that if I have 'Worksheets("Formula Sheet #" & FormSheet).Activate'
statement in there I get an error. I've tried putting it in various
locations and still get the same error. If I leave it out, the Ranges on the
command button sheet get selected and merged in the same manner as I want the
ranges on the Formula Sheet to be selected and merged.

Also, I have tried moving the actual Range Selection statement to a location
outside of the IF Then but get a 400 error. If anyone has any ideas on how
to activate the formula sheet and select the ranges based on the LeftRight
idea please let me know. All the variable are public so they can be used
with any of the command buttons.

Thanks,

Chaz
 
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
.Activate vs. .Select in VBA Dave F Excel Discussion (Misc queries) 1 January 24th 07 03:41 PM
what's the difference between Activate and Select for Worksheet? lvcha.gouqizi Excel Programming 1 October 28th 05 05:53 PM
Smart use of .Activate; .Select; .Copy with Sheets(1) va Worksheet Dennis Excel Discussion (Misc queries) 5 July 24th 05 01:05 AM
select vs activate Ron de Bruin Excel Programming 0 September 9th 04 04:05 PM
select vs activate Chip Pearson Excel Programming 0 September 9th 04 04:02 PM


All times are GMT +1. The time now is 03:24 AM.

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"