There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Business Applications
Tag Cloud
adware audio bios blue screen boot bsod computer crash dell desktop driver drivers email error excel firefox freeze google hard drive hardware hijackthis install internet laptop linux malware network no sound outlook problem router screen server slow sound speakers spyware startup trojan usb video virus vista vundo webcam windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Excel 2003 VBA

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
computerman29642's Avatar
Computer Specs
Distinguished Member with 2,565 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
16-Jun-2008, 02:46 PM #1
Solved: Excel 2003 VBA
I am trying to create a VBA that run when the workbook is opened. If D8 is not blank, then the next cell (E8) will be selected. If D8 is blank, then D8 will be selected. The code needs to look through cell I8.
Rollin_Again's Avatar
Distinguished Member with 3,709 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
16-Jun-2008, 04:31 PM #2
Open the Excel workbook. Just to the left of the FILE menu is a small Excel icon. Right click it and select VIEW CODE. When the VBA editor opens look for the combobox at the top of the editor that says "General." Change this value to "Workbook" and the Workbook_Open sub should be created automatically for you. This is where you put your code. Instead of using multiple IF statements you should use a loop to evaluate each cells until you find the first empty cell that meets your condtions. I can help with the loop but need to know what happens if all cells between D8 and I8 contains values?

Code:
Private Sub Workbook_Open()

If IsEmpty(Range("D8")) Then
Range("D8").Select
Else
Range("E8").Select
End If

End Sub



Regards,
Rollin

Last edited by Rollin_Again : 16-Jun-2008 05:44 PM.
computerman29642's Avatar
Computer Specs
Distinguished Member with 2,565 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
16-Jun-2008, 04:54 PM #3
Quote:
I can help with the loop but need to know what happens if all cells between D8 and I8 contains values?
If cells between D8 & I8 contain values, then I would like for cell K4 to be selected.
Rollin_Again's Avatar
Distinguished Member with 3,709 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
16-Jun-2008, 05:11 PM #4
Here are a couple of different ways you can do this

Code:
Private Sub Workbook_Open()

For Each vCell In Range("D8:I8")
If IsEmpty(vCell) Then
vCell.Select
Exit Sub
End If
Next
Range("K4").Select

End Sub
or

Code:
Private Sub Workbook_Open()

If Application.Evaluate("COUNTA(D8:I8)") = 6 Then
Range("K4").Select
Else
vStartCol = 4
If IsEmpty(Cells(8, vStartCol)) Then
Cells(8, vStartCol).Select
Else
Do While vStartCol <= 9 And Not IsEmpty(Cells(8, vStartCol))
vStartCol = vStartCol + 1
Loop
Cells(8, vStartCol).Select
End If
End If

End Sub
Regards,
Rollin

Last edited by Rollin_Again : 16-Jun-2008 05:49 PM.
computerman29642's Avatar
Computer Specs
Distinguished Member with 2,565 posts.
 
Join Date: Dec 2007
Location: HERE OR THERE?!?!?!
Experience: Always Learning!
17-Jun-2008, 08:02 AM #5
Thnaks Rollin. The code(s) you provided works great.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 12:52 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.