Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all 50068 articles
Browse latest View live

Filtering a list of Names from Worksheet1 onto Worksheet 2 based on specific criteria

$
0
0
The first worksheet contains registered voter information including whether or not they voted in the last 4 primary elections. If they did vote in the last four primaries, the relevant cells are populated with a label "A" for Absentee, or "P" for Polls indicating how they voted. These labels are found in the following columns:

2006 Primary = "CF"
2008 Primary = "CC"
2010 Primary = "BZ"
2012 Primary = "BW"

I need to filter that information based on election year. I have created a second worksheet with check boxes for 2012, 2010, 2008, & 2006. When I click on a box, I want a list of voters who voted in that year to populate down the page. If I select multiple years, it should only populate those voters that voted in ALL of the years selected. I have attached a copy of the workbook.

Can anyone advise the best way to approach this?
Attached Files

VBA goal seek multiple cells

$
0
0
Hello,

I want to goal seek several different cells.
First, I want to change cell A1 by setting cell B1 to 0. However, A1 takes into account the value of C1.
Then I want to change cell A2 by setting cell B1 to 0. However, I want the value of C1 to have 5 added to it before goal seeking.

Anyone know VBA for this?

[SOLVED] VBA Code - Expand/Collapse Grouped Columns

$
0
0
Hello all,

Currently, Columns EFG are grouped.

I have a userform with checkboxes. With the click of check box, i would like for it to do the following.

If checked, it will expand the group. If unchchcked, it needs to stay collapsed.

Here is an example of code i currently have and is not working.
Code:

If CheckBox1.Value = True Then Worksheets(ActiveSheet.Name).Columns("e,f,g").Cells = expand
If CheckBox1.Value = false Then Worksheets(ActiveSheet.Name).Columns("e").Cells = collapse

any help will be much appreciated

Macro to Match Column Against Row Criteria

$
0
0
Hello all,

Trying to write a macro that will display either an “X” or a date under a specific header if several conditions are met across a row in another tab.

I have two tabs, one is the report, the other raw data. On the raw data tab, if the macro finds a row where the title, territory, Rowdesc, start and end dates all match criteria, then display an “X” next to that title in the report tab.
The criteria would be:

Title Match - between Raw Data tab and Report tab
Terr_Nm column matches report header in Report Tab
Rowdesc = “No Rights”
Start Date = the date 1-Jan-1900 or 1
End Date = * - an asterick

However, if the macro finds a start date that is greater than today, display this start date on the report where the “X” would normally go. If the macro finds a start date that is less than today and an end date that is greater than today, then display the end date where the “X” would normally go.

If the macro does not find anything, then do nothing and go on to the next row. In my example, “Title 4” isn’t on the raw data, so the macro would do nothing with this title.

Raw Data:

Raw Data.jpg

Report Tab, before and after running macro:

Raw Data 2.jpg

I’ve tried doing this with formulas (dcount, countif, etc.) and the problem is displaying the specific date. So, I’d like to use VBA to automate.

Any help is most appreciated! Thank you!

Question also posed at: http://www.mrexcel.com/forum/excel-q...ml#post3713714
Attached Images

LOOK UP, COPY PASTE into Another Sheet Within SAME Workbook - with TODAY Date

$
0
0
Need help expanding this code to make it do the following:
1. Start w/ "RULE-Table" sheet,
2. Take note of "TODAY" date,
3. LOOKUP date in "RULE-table"
4. Locate Coordinates found in Col D of RULE-Table,
5. LOOKUP the data that resides in those Coordinates on the "PRODUCTION" sheet & COPY
6. PASTE data into "REPORT" tab C2 and E2.

Here's an example to help visualize:
Code will do everything it needs to do within an Undisclosed OPEN file with several sheets.
The reason the Workbook file name is undisclosed/undefined is because the file name will vary based on clients, so I don't want the code to be limited to look for a specific filename.

*The sheet names within this OPEN client file will always have the same names.


The sheet called: "RULE-Table" holds coordinates based upon "TODAY's" computer date.
For example: If today is JAN 4, the desired coordinates to pull data from are "B5" and "D10" from the "PRODUCTION" sheet.


"RULE-Table" sheet
A......B.........C................D.......
Row1.DAY....WK RANGE....QTR RANGE
2......1/1.......1...............B2,D7
3......1/2.......1...............B3,D8
4......1/3.......1...............B4,D9
5......1/4.......1...............B5,D10
6......1/5.......1...............B6,D11

Since today is 1/4, its rules say go to B2 and D10 of the PRODUCTION tab and collect the data

"PRODUCTION" (data source) sheet (within the same open file)
A.......B......C....D....E....F...
Row1..Header..Hdr..Hdr..Hdr..Hdr.
2.......2.................................
3.......14...............................
4.......13...............................
5.......20...............................
6.......62..............................
7....................76.................
8...................184................
9...................375................
10.................410................
11.................525...............

Last, the collected data from those 2 coordinates should always get pasted onto the "REPORT" tab
into C2 and E2 in this example.

"REPORT" (destination) sheet (within the same open file)
A........B.........C.....D....E.....
Row1..Header..Hdr..Hdr..Hdr..
2...................20........410......

Code:

Sub LookupRulesCopyPasteResults()


    ' -----------------------------------------------------------------------------------------
    ' Define variables
    ' -----------------------------------------------------------------------------------------
    Dim strFilename As String
    Dim strWorkbookName As String
    Dim objInputWB As Workbook
    Dim objExtractWB As Workbook
    Dim oWB As Workbook, oWS As Worksheet
    Dim lngLastRow As Long, bFound As Boolean
   
    ' -----------------------------------------------------------------------------------------
    ' Find workbook with Worksheet named "RULE-Table" Worksheet
    ' -----------------------------------------------------------------------------------------
    For Each oWB In Workbooks                      ' cycling through each open workbook
        For Each oWS In oWB.Sheets                ' cycling through each sheet of each workbook
            If oWS.Name = "RULE-Table" Then ' comparing the sheet name to find the one we are looking for
                Set objInputWB = oWB
                bFound = True
            End If
            If bFound Then Exit For
        Next oWS
        If bFound Then Exit For
    Next oWB
    Set oWB = Nothing
   
     
   
    ' -----------------------------------------------------------------------------------------
    ' Advise user and terminate program if we cannot find the approprate workbook.
    ' -----------------------------------------------------------------------------------------
    If Not bFound Then
        MsgBox Prompt:="Unable to find data's destination 'RULE-Table', Please make sure your Client WB is open - terminating this transfer attempt!", _
              Buttons:=vbCrtical, _
              Title:="Export"
        Exit Sub
    End If
    ' -----------------------------------------------------------------------------------------
    ' Lookup TODAY date (based on Computer's date)
    ' -----------------------------------------------------------------------------------------
    ' xxxxx

    ' -----------------------------------------------------------------------------------------
    ' Lookup that date on the "RULE-Table" tab
    ' -----------------------------------------------------------------------------------------
    Sheets("RULE-Table").Select 
    ' xxxxx

    ' -----------------------------------------------------------------------------------------
    ' Take note of the Coordinates found in Column D of the "RULE-Table" tab
    ' -----------------------------------------------------------------------------------------
 
    ' xxxxx

    ' -----------------------------------------------------------------------------------------
    ' Lookup data residing in those Coordinates on the "PRODUCTION" tab & COPY those 2 cells C2 & E2
    ' -----------------------------------------------------------------------------------------
    Sheets("PRODUCTION").Select

    Range("C2").Select
    Selection.Copy

    Sheets("REPORTS").Select
    Range("E2").Select
    Selection.Copy
   
    ' xxxxx

    ' -----------------------------------------------------------------------------------------
    ' Last, PASTE that data into Cell "C2" and Cell "E2" of the "REPORT" tab
    ' -----------------------------------------------------------------------------------------   
    Sheets("REPORTS").Select

    Range("C2").Select
    ActiveSheet.Paste
    Range("A3").Select

    Range("E2").Select
    ActiveSheet.Paste
    Range("E2").Select
   
    ' xxxxx
    ' -----------------------------------------------------------------------------------------
    ' Tell the Analyst that the Client's Data was Successfully Transferred to the Report
    ' -----------------------------------------------------------------------------------------

    MsgBox "Transfer of Production Data to Report is Complete!"

End Sub

:confused:

automatically creating .csv files from .txt files with specific format and formula

$
0
0
I am novice user in Macros. Could anyone help please?
The project is divided in 2 parts.
1) As attached, the input files are in .txt format and all files we are saving in same drive so for e.g. C: / and I want to convert that all file in .csv format. So I was just wondering is it possible to design macro which will read all .txt files in specific folder and create .csv files.


2) If I converted that .txt file in to the excel it will looks like example 1


3) I just added the formula in column C as following
=IF((F1-D1)*24<0,(F1-D1+1)*24,((F1-D1)*24)) and then I will receive the output like as example 2


4) In final .csv file only 3 columns are required which is as example 3

Employee number, total hours worked and date (which is in DD/MM/YYYY)
The total hours worked are formatted to 2 digits.


I am also attaching .txt file and actual excel files.

Thanks in advance.
Attached Images
Attached Files

VBA copy past

$
0
0
How can I copy the cell F36 to Cells in range?

I have a loop with a lot going on. After calculations, I want to copy cell F36 to cell F15,then add 5 to cell A1, then copy F36 to F16 etc

Any help?

Sending email based on the information in an excel sheet?

$
0
0
I have a file with the following columns:

ID Number - Name - Email - Comments

Is there a way that for each row and email is sent with the ID number, name and comments?

Thanks!

Printing multiple pages from different Worksheets into single PDF

$
0
0
Hi everyone,

A new member here and had a question regarding print automation within VBA functionality.

I have setup macros in the past to print multiple sheets to a single PDF using something simple like this:

Sheets(Array("Sheet 1", "Sheet 2", "Sheet 3")).Select
Application.Dialogs(xlDialogPrint).Show

I have a few more complexities now and wish to print pages from multiple sheets.

Example:

I want to print a single PDF document containing->
Sheet 1 : Pages 1 - 5
Sheet 2 : Pages 1 - 2
Sheet 1 : Pages 6 - 7
Sheet 3 : Pages 1 - 2

Any help around how I would go about setting this up would be greatly appreciated.

Thanks,
Chris

ComboBox on worksheet linked to a cell

$
0
0
Hi there. This is my first posting. I have a worksheet, and I want to place a combobox in a cell, but being able to add values not on the corresponding list. Done almost everything, but cannot find a way to use the position of the cell, so I can dinamicly place a combobox. Ex.- place a combo in a cell, then after you get the value, delete the combo and put it in the cell bellow, etc. In order to do this I need the position of the cell: left, right, height, width. How can I get this information? Thank you

Macro copying formula where i only want the values

$
0
0
Hi there

I have the following macro which works fine accept for the fact that it copies the formulas from other worksheets, where as i only want to copy the values. Can someone please help?

Private Sub Worksheet_Activate()
Dim Sheet As Worksheet
For Each Sheet In Me.Parent.Sheets
If Sheet.Name <> Me.Name Then
If Sheet.Cells(Rows.Count, 1).End(xlUp).Row <> 1 Then
Sheet.Range(Sheet.Cells(2, 1), Sheet.Cells(Sheet.Cells(Rows.Count, 1).End(xlUp).Row, 8)).Copy Destination:=Me.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)

End If
Else
Me.Range(Cells(2, 1), Cells(Rows.Count, 8)).Clear
End If
Next Sheet
End Sub

Macro to create unique id from email address and assign to repeated entries

$
0
0
Hello, I need help.

I am creating a rollup file from hundreds of excel files each has the same structure

Each file will have a dozens to hundreds of names and some files will share entries i.e Juan Alvarez might be in 10 different files

I need to create a unique numerical identifier starting at 0 for everyone based off there unique email address for each individual in the rollup file

So Juan Alvarez would need to be given the same numerical ID every time he showed up in the rollup


Thanks

Code:

File1
Name        email
Bob Johnson  bobjohnson@email.com
sue Berg    sueberg@email.com
 .              .
 .              .
 .              .
Juan Alvarez Juanalvarez@email.com
.

File2 
Name          email
Joe Jenson    joejenson@email.com
Juan Alvarez  Juanalvarez@email.com
sally Bergson  sallybersong@email.com
 .                .
 .                .
 .                .
Frank Carpet  frakkcarpet@email.co
Bob Johnson    bobjohnson@email.com
.

Rollup
Name        email                    ID
Bob Johnson  bobjohnson@email.com      0
sue Berg    sueberg@email.com        1
 .              .
 .              .
 .              .
Juan Alvarez Juanalvarez@email.com    17
Joe Jenson    joejenson@email.com    18
Juan Alvarez  Juanalvarez@email.com  17
sally Bergson  sallybersong@email.com  19
 .                .
 .                .
 .                .
Frank Carpet  frakkcarpet@email.com  53
Bob Johnson  bobjohnson@email.com      0

Copying sheets from a closed workbook - Excel 2013 crashes Sheets.Add

$
0
0
In Excel 2010 I used this code to import sheets from a closed workbook in the same folder as my master workbook:

Code:

ActiveWorkbook.Sheets.Add Type:=ThisWorkbook.Path & "\" & "OTHEREXCELFILE.xlsx"
In Excel 2013 this command seems to crash the Excel Application. Is there another way to import sheets from a closed excel file into a master excel file? Or is there a way to prevent Excel 2013 from crashing?


here is the problem signature for the error:

Problem signature:
Problem Event Name: APPCRASH
Application Name: EXCEL.EXE
Application Version: 15.0.4551.1510
Application Timestamp: 528be48d
Fault Module Name: EXCEL.EXE
Fault Module Version: 15.0.4551.1510
Fault Module Timestamp: 528be48d
Exception Code: c0000005
Exception Offset: 00054191
OS Version: 6.1.7600.2.0.0.768.3
Locale ID: 1033

Separate data in a Cell using Macro.

$
0
0
Hi guys, I need help here.

I got a column of data in format as below:

Column 1:
ABC - AC123
ASD - DS335
BBC - KK311
SWT - TR735
TIM - DN849

Between two texts to be separate, there is a " - ", we can separate them with that symbol right?..The cells should be look like after separate shown belows:

Column 1:
ABC
ASD
BBC
SWT
TIM

Column 2:
AC123
DS335
KK311
TR735
DN849

What is the macro code to do this, anyone can help me?

Need someone to create GUI for excel spreadsheet!

$
0
0
I have a spreadsheet I use for my business that calculates my cost to build a given project. The spreadsheet has many calculations and I would like to be able to have a GUI for my salespeople to just enter information about the project and it fills those cells that do the calculations.

Any ideas? Thank you!

Need help with VBA code for filtering/arranging data

$
0
0
Hi,

I have an excel file which contains:

columA columB columC columD
ABC45 2502 .... etc
ABC45 2503
ABC45 2504
DSE76 6589
DSE76 5123
FG345 5464
GFDR4 5422
etc...

I need to arrange it this way:

ABC45 2502 2503 2504
DSE76 6589 5123
FG345 5464
GFDR4 5422


Any trick to make this works ?
or can only work it out with VBA ?

Delete row based on input

$
0
0
Hi experts,

I would like a macro that prompts me to input the value of "pay period" column K. The macro should delete all rows except for where column K equals my input.

Sample sheet is attached. Thanks
Attached Files

[SOLVED] Using a Variable to set PivotFields gives me an Error

$
0
0
Howdy Folks;

I have attached a file that shows what I'm attempting to do. I have a loop (that is not shown) that changes the name of the pivot table field names on each iteration. I'm currently doing months. In the case that I have shown I'm trying to dynamically choose the pivotfield name to "Feb". "Feb" is a choice in the field list. If I use "Feb" it works fine. But I have set a variable called ShortMon to "Feb" (actually a MID function sets it). In the VBE I have shown the different attempts. The error is : 1004 Unable to get the PivotFields Property of the PivotTable Class. I'm definitely open to suggestions.

thanks for the help...

Ernest
Attached Files

Macro to consolidate data from multiple sheets to one

$
0
0
hey all

i have the following macro, however I am struggling to make it work on my file:

Code:

Private Sub Worksheet_Activate()
Dim Sh As Worksheet
Dim Newsh As Worksheet
Dim LR As Long, NR As Long

Application.ScreenUpdating = False

Set Newsh = ThisWorkbook.Sheets(Sheet1.Name)
Newsh.Range("A1").CurrentRegion.Offset(1).Clear
NR = 9

   
    For Each Sh In ThisWorkbook.Worksheets
        If Sh.Name Like "*" And Sh.Name <> Sheet1.Name And Sh.Visible Then
            LR = Sh.Range("B" & Sh.Rows.Count).End(xlUp).Row
            If LR > 8 Then
                Sh.Range("A2:U" & LR).Copy
                Newsh.Range("C" & NR).PasteSpecial xlPasteValues
                Newsh.Range("C" & NR).PasteSpecial xlPasteAll
                LR = Newsh.Range("C" & Rows.Count).End(xlUp).Row
                Newsh.Range("B" & NR, "B" & LR) = Sh.Name
                NR = LR + 1
 
            End If
        End If
    Next Sh

    If NR > 9 Then
    Range("A2:A" & NR - 1).Formula = "=row(A1)"
    End If
   
 
    With Newsh.Range("A1").CurrentRegion.Font
        .Name = "Arial"
        .Size = 8
    End With
       

Application.ScreenUpdating = True
End Sub

i have attached my sample. essentially i have the dec, jan etc month tabs to consolidate into the summary sheet. i would like the data to be dumped from both sheets into the summary sheets. i will be adding a feb, march, april etc tabs as the year progresses.

i would also like column A in the summary sheet to repeat the name of the sheet the data is being retrieved from.

pls help..not sure what the issue with the macro above is :S
Attached Files

Create Workbook with 7 Passwords

$
0
0
I am looking for some help in writing a macro for an excel spreadsheet. Here is what I would like to create.

I have a spreadsheet with 9 worksheets total.

7 of these worksheets are linked to 7 different users. The other 2 worksheets are based on links from these 7 worksheets.

As we speak a user must open the file unprotect his user sheet put the info needed and then protect it once again.
As many of you know many times people forget to protect their worksheet and other users can go in and manipulate the worksheet.

What I would like to create is an excel file that opens up with 7 different passwords. All of these passwords are able to open the excel spreadsheet. However each password is only linked to a specific user worksheet. Each password is only linked to their own personal worksheet. Meaning the password can read and write on this one worksheet but only read the other 8. I also would like to add an automatic save upon exiting. I would also like a password for the administrator to read and write on all 9 worksheets.

Is this possible??

Thank you for your help :)
Viewing all 50068 articles
Browse latest View live