473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Excel VB question

Stang02GT
1,208 Expert 1GB
I know very little about excel and if anyone has looked through the Access forum i am just gettting my feet wet with VB coding.

Is it possible to do VB code in Excel that will look at a column F in all four of my tabs, and if a cell in the column F says "completed" it will be moved to another Tab Called "completed" in my work book?
Jul 24 '07 #1
11 1235
IMAPD
2
It is possible to Code in Excel . Its called writing macros.
Press Alt+F11 On the excel sheet on which you need to do the coding the editor will open, there you will find various events on which you can write your code.
However VBA is a subset of Vb so you will not find all the features supported by VB.
Jul 25 '07 #2
Stang02GT
1,208 Expert 1GB
It is possible to Code in Excel . Its called writing macros.
Press Alt+F11 On the excel sheet on which you need to do the coding the editor will open, there you will find various events on which you can write your code.
However VBA is a subset of Vb so you will not find all the features supported by VB.

I have developed a macro to do this, what event should i place it in?
Jul 25 '07 #3
MikeTheBike
639 Expert 512MB
I have developed a macro to do this, what event should i place it in?
OK, so you have written the code. How/when/where do you want this to run?

You could just put a button on the sheet and click it !?
It is possible to Code in Excel . Its called writing macros.
BTW as fare as I an concerned a macro is something you record. VBA can do very much more than you can do just clicking buttons on a toolbar. You can write programms in Excel that don't use spreadsheet functionality at all. Why would you? Because I don't have VB6 or .NET available at work.

Sorry about the rant!

MTB
Jul 25 '07 #4
Stang02GT
1,208 Expert 1GB
OK, so you have written the code. How/when/where do you want this to run?

You could just put a button on the sheet and click it !?

BTW as fare as I an concerned a macro is something you record. VBA can do very much more than you can do just clicking buttons on a toolbar. You can write programms in Excel that don't use spreadsheet functionality at all. Why would you? Because I don't have VB6 or .NET available at work.

Sorry about the rant!

MTB


I would like it to run as soon as the spread sheet is opened, if i can have it run automatically that would be great, opposed to the user pressing a button.

Here is my code also

Expand|Select|Wrap|Line Numbers
  1. Dim lLastRow As Long, lRow As Long, lCompRow As Long
  2. Dim wsShts As Worksheet, wsComplete As Worksheet
  3.  
  4. Set wsComplete = Sheets("Completed")
  5. lCompRow = wsComplete.Cells(Rows.Count, 1).End(xlUp).Row + 1
  6.  
  7. For Each wsShts In ThisWorkbook.Worksheets
  8.  
  9.     If wsShts.Name <> "Completed" Then
  10.         lLastRow = wsShts.Cells(Rows.Count, 1).End(xlUp).Row
  11.         For lRow = 2 To lLastRow
  12.             If UCase(wsShts.Cells(lRow, 6).Value) = "COMPLETED" Then
  13.                 wsShts.Range("A" & lRow).EntireRow.Copy
  14.                 wsComplete.Range("A" & lCompRow).PasteSpecial
  15.                 lCompRow = lCompRow + 1
  16.             End If
  17.         Next lRow
  18.     End If
  19.  
  20. Next wsShts
  21.  
Jul 25 '07 #5
MikeTheBike
639 Expert 512MB
I would like it to run as soon as the spread sheet is opened, if i can have it run automatically that would be great, opposed to the user pressing a button.

Here is my code also

Expand|Select|Wrap|Line Numbers
  1. Dim lLastRow As Long, lRow As Long, lCompRow As Long
  2. Dim wsShts As Worksheet, wsComplete As Worksheet
  3.  
  4. Set wsComplete = Sheets("Completed")
  5. lCompRow = wsComplete.Cells(Rows.Count, 1).End(xlUp).Row + 1
  6.  
  7. For Each wsShts In ThisWorkbook.Worksheets
  8.  
  9.     If wsShts.Name <> "Completed" Then
  10.         lLastRow = wsShts.Cells(Rows.Count, 1).End(xlUp).Row
  11.         For lRow = 2 To lLastRow
  12.             If UCase(wsShts.Cells(lRow, 6).Value) = "COMPLETED" Then
  13.                 wsShts.Range("A" & lRow).EntireRow.Copy
  14.                 wsComplete.Range("A" & lCompRow).PasteSpecial
  15.                 lCompRow = lCompRow + 1
  16.             End If
  17.         Next lRow
  18.     End If
  19.  
  20. Next wsShts
  21.  
OK, so where is this code going be placed?
Is in the book that ThisWorkbook is refering to in the code, or in some other workbook ? If it is the fosrt option, then just place it in the ThisWorkbook module Workbook_Open event, if not, it gets a little more complicated.

Let me know.

MTB
Jul 25 '07 #6
Stang02GT
1,208 Expert 1GB
Right now i have the code in a module and would like it to run as soon as the workbook is opened.
Jul 25 '07 #7
MikeTheBike
639 Expert 512MB
Right now i have the code in a module and would like it to run as soon as the workbook is opened.
Have you tried starting it in the Workbook_Open like I suggested?

MTB
Jul 25 '07 #8
Stang02GT
1,208 Expert 1GB
Yes i tried to put it in there like you suggested.

Sorry i will explain to you what the code is trying to do

I have a workbook with 5 tabs one being a completed tab. THis workbook keeps track of projects that are in our business. In the F column of every sheet is a status of the projects. I would like that if the status is changed to "completed" the entire record be moved to the completed tab of the workbook.
Jul 25 '07 #9
Stang02GT
1,208 Expert 1GB
Ok i have gotten the code to work. It runs through all my records and copies anythign that is completed and pastes it in the completed tab of the workbook.

Now my issuse is how can i delete the rows that i copied and pasted. Whats the best way to do this...have something that runs through and deletes the records i copied?

here is my code

Expand|Select|Wrap|Line Numbers
  1. Sub CompActions()
  2.  
  3. Dim lLastRow As Long, lRow As Long, lCompRow As Long
  4. Dim wsShts As Worksheet, wsComplete As Worksheet
  5.  
  6. Set wsComplete = Sheets("Completed")
  7. lCompRow = wsComplete.Cells(Rows.Count, 6).End(xlUp).Row + 1
  8.  
  9. For Each wsShts In ThisWorkbook.Worksheets
  10.  
  11.     If wsShts.Name <> "Completed" Then
  12.         lLastRow = wsShts.Cells(Rows.Count, 6).End(xlUp).Row
  13.         For lRow = 2 To lLastRow
  14.             If Left(UCase(wsShts.Cells(lRow, 6).Value), 4) = "COMP" Then
  15.                 wsShts.Range("A" & lRow).EntireRow.Copy
  16.                 wsComplete.Range("A" & lCompRow).PasteSpecial
  17.                 lCompRow = lCompRow + 1
  18.             End If
  19.         Next lRow
  20.    End If
  21.  
  22. Next wsShts
  23.  
  24. End Sub
Jul 26 '07 #10
MikeTheBike
639 Expert 512MB
Hi

Try this and see if it does wat you require

Expand|Select|Wrap|Line Numbers
  1. Sub CompActions()
  2.  
  3. Dim lLastRow As Long, lRow As Long, lCompRow As Long
  4. Dim wsShts As Worksheet, wsComplete As Worksheet
  5.  
  6. Set wsComplete = Sheets("Completed")
  7. lCompRow = wsComplete.Cells(Rows.Count, 6).End(xlUp).Row + 1
  8.  
  9. For Each wsShts In ThisWorkbook.Worksheets
  10.  
  11.     If wsShts.Name <> "Completed" Then
  12.         lLastRow = wsShts.Cells(Rows.Count, 6).End(xlUp).Row
  13.         For lRow = 2 To lLastRow
  14.             If Left(UCase(wsShts.Cells(lRow, 6).Value), 4) = "COMP" Then
  15.                 wsShts.Range("A" & lRow).EntireRow.Copy
  16.                 wsComplete.Range("A" & lCompRow).PasteSpecial
  17.                 lCompRow = lCompRow + 1
  18.             End If
  19.         Next lRow
  20.  
  21.         For lRow = lLastRow To 2 Step -1
  22.             If Left(UCase(wsShts.Cells(lRow, 6).Value), 4) = "COMP" Then
  23.                 wsShts.Row(lRow).Delete
  24.             End If
  25.         Next lRow
  26.    End If
  27.  
  28. Next wsShts
  29.  
  30. End Sub
??

MTB
Jul 27 '07 #11
Stang02GT
1,208 Expert 1GB
Awsome it worked! Thanks Mike!
Jul 27 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL...
6
by: Sam Johnson | last post by:
HI I tried to send the following SQL string to an open databse, to export a table into excel format: g.Connection = conn 'valid OleDBConnection and Command objects g.CommandText = "SELECT *...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
19
by: wreckingcru | last post by:
I'm trying to output a SQL query that is constructed thru my VB.net GUI into an excel file. Here is the code I'm using: 'Sqlstmt is the SQL query statement 'Conn is the SQL Connection object...
2
by: Mad Scientist Jr | last post by:
>From an asp.net web page I want the user to open the results of a SQL query in Excel, as automatically as possible (ie not having to loop through columns, rows, in code). For this,...
6
by: Gunawan | last post by:
Dear All, I have create an excel (COM Object) using this code Excel.Application xls = new Excel.Application(); but I can not remove it from memory although I have using close and quit ...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
7
by: ddecoste | last post by:
I have a need to add a visual representation to some data in Access. I need to draw a matix of squares inside another square. I have all the data that I need in a record in Access. The data...
3
by: pleaseexplaintome_2 | last post by:
using the code below (some parts not included), I create a new excel workbook with spreadheets. I then want to delete a spreadsheet, but a reference remains open and excel stays in task manager...
3
by: akristensen | last post by:
I am new to this site, so be patient if I do not ask the question correctly. Current Target Platform: Browser: MS IE, script language: Javascript (will use VBScript, but JS is preferred), External...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.