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

Split workbook sheets in seperate sheets

$
0
0
Hi forum,


Greetings...!

Pls help me in solving excel query of splitting big workbook into multiple or separate sheets.

Request solution for my problem..

Syntax For CountIf Using Variables

$
0
0
Hi, I cant figure out the syntax for CountIf, Im trying to add the following variables to countif, but I keep getting errors.

Thanks, much appreciated.

Code:

Sub ValleysDips()


 Dim ValuesRange As Range
 Dim ValuesRange As String
  Dim ResultCell As Range
  Dim CriteriaValue As String

  Set ValuesRange = Range("A1:A10")
  Set ResultCell = Range("C3")

  CriteriaValue = "A1"

  Range(ResultCell) = Application.WorksheetFunction.CountIf(Range(ValuesRange), "<" & Range(ResultCell))


End Sub

Attached Files

User Form Command Button

$
0
0
Attached is a small sample of my workbook. When the workbook is opened only the summary page is visible. There will be over 100 records. A person clicks the record it hyperlinks to the sheet. On that page I would like a command button for the User Form I created. I'm not sure if the problem is in the User Form coding or in the coding I was using for the command button. It should be as simple as userform1.show but it's not working. I need the user form to pop open and fill in the table on the right side. Any help would be greatly appreciated.

Thank you
Attached Files

Loop through XML file and get nodes

$
0
0
Hi

This is my first post on this website, i've been using the forum alot over the years, but the time has come for me to post a problem that i cant solve myself.

I'm trying to get some data from a XML file, my issue is that the XML file can vary, but the node names will be the same, but the amount of nodes will vary. I've attached a picture of the issue.

The Data does not come in the same order as in the XML. I've attached both the excel and the XML that i i've tested it on.

Img.PNG

Code:

Sub GetAllData()

Dim mainworkbook As Workbook
    Set mainworkbook = ActiveWorkbook
    Set oXMLFile = CreateObject("Microsoft.XMLDOM")
    XMLFileName = ActiveSheet.txtPath.Text
    oXMLFile.Load (XMLFileName)
    Set TitleNodes = oXMLFile.SelectNodes("/MarkupSummary/Markup/Emne/text()")
    Set IntNodes = oXMLFile.SelectNodes("/MarkupSummary/Markup/Forfatter/text()")
    Set SideetiketNodes = oXMLFile.SelectNodes("/MarkupSummary/Markup/Sideetiket/text()")
    Set KommentarerNodes = oXMLFile.SelectNodes("/MarkupSummary/Markup/Kommentarer/text()")
    Set Markup = oXMLFile.SelectNodes("/MarkupSummary")
       
        x = 1
        r = 5
       
        Set list = oXMLFile.SelectNodes("/MarkupSummary")
       
        For i = 0 To (TitleNodes.Length - 1)
 
            Title = TitleNodes(i).NodeValue
            Forfatter = IntNodes(i).NodeValue
            Sideetiket = SideetiketNodes(i).NodeValue
            Kommentarer = KommentarerNodes(i).NodeValue
            Debug.Print i
           
                If Title Like "Bemærkning*" Then
                mainworkbook.ActiveSheet.Range("E" & r).Value = Forfatter
                mainworkbook.ActiveSheet.Range("B" & r).Value = Sideetiket
                mainworkbook.ActiveSheet.Range("C" & r).Value = Title
                mainworkbook.ActiveSheet.Range("D" & r).Value = Kommentarer
                mainworkbook.ActiveSheet.Range("A" & r).Value = x
               
                x = x + 1
                r = r + 1
                End If
               
        Next
    'ActiveSheet.txtPath.Text = ""

End Sub

I hope some of you have the time and to help me.
Attached Files

Code to Create Hyperlink to Newly Created Worksheet

$
0
0
Hello, my name is Carlos and I'm new to this forum. I have a workbook named "TP Tracking Log" used to track test procedure development. It consists of 2 worksheets: Log and Template. When an entry is made in column A (TP #), it creates a copy of the Template named whatever was entered in the cell under column A. What I would also like it to do is create a hyperlink in that cell in column A to the newly created worksheet. I have have attached the workbook. Any help would be greatly appreciated! Thanks in advance for your quick response!
Attached Files

Multiple drop down lists, all dependent of the same previous drop down list + Combination

$
0
0
Hello everyone,

**EDIT : See attachment for better understanding**

I have two problems, If you could help me solve them I would really appreciate :p


1. I've been working with dependent drop down lists recently, I figured out how to make dependant cascading drop down lists using DataAnalysis (=INDIRECT) and applying names to my lists. My problem is that this technique only let me make one list dependent of one other.

What I would like to do is have one list that influences many others (one list to rule them all).

For example, I am working with a list of "Fields" (Ex: field 1, 2 and 3) and each field have different lists of "parameter", "model" and "method". To make it clear, the methods and parameter are dependent of the field, but the methods and parameters are independent regarding each others.

How could I make it so that choosing a certain field in a drop down list would restrict the parameter drop down list AND the methods AND the model drop down list ?


2. In this same scenario, I have Different fields that restrict different parameters . I would like to be able to select more than one field, and then the dependent drop down list would contain the selections of the two fields at the same time, let it be understood that I dont want to select the fields on the same drop down list, but on different drop down lists.(same thing for model and methods)


I Hope all this is possible
Thank you,
Justin

Userform issues list boxes moving location and form resizing

$
0
0
Hi,

Im wondering if anyone has come across similar issues and how these were resolved.

I am updating a workbook which has a number of userforms and is linked to an external database held on a server.

There seems to be issues with a couple of large userforms on this workbook.

These were created using Excel 2013 but are now being updated with Excel 365 (desktop), build 1902.

The set up for viewing is a Surface Pro 4, with screen extended via a hub to 2 additional monitors (1920x1068).

1) When selecting options in a list box the userform will flicker and the location of the list boxes changes, but if you then drag the userform even just a tiny bit the userform returns to normal.

2) when viewing the form from the code editor the form appears much larger. like its being zoomed in.
But if you attempt to adjust the height/width then the contents of the form snap back to normal, but the height and width remain the same and has to be adjusted.


These things happen even when the height/width are defined.

Note: There is a seperate function within the code that sets the opening point of the form as the centre of the screen where the workbook is opened.

I have tried blocking this code in case it was this causing the issues, but they still happen.


I have tried using the option to get the best resolution/view etc but this reduces the size of the user form and its not suitable for use. However, could this be used and then zoom in to the userform? could that resolve the issue?

new to vba, need some help with if code

$
0
0
Hi there, i am new to vba coding and i need some help with a code i made.
I am trying to build a code that will add a new row to a table automatically if the current month is greater then the newest month that is currently in the table
for example if the latest row shows info for December 2019 than the code will add a new row for January 2020. here is the code i made:
Code:

Sub NewMonthChck()
   
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("T.value")
    Dim n As Long
    n = sh.Range("A" & Application.Rows.Count).End(xlUp).Row
    If (Month(Now) > Month(Cells("n", 1).Value)) Then
        sh.Range("A" & n + 1).Value = Date
        sh.Range("B" & n + 1).Value = Range("B4").Formula
        sh.Range("C" & n + 1).Value = Range("C4").Formula
        sh.Range("D" & n + 1).Value = Range("D4").Formula
        sh.Range("E" & n + 1).Value = Range("E4").Formula
        sh.Range("F" & n + 1).Value = Range("F4").Formula
        MsgBox "A new month has started"
    End If

End Sub

When i try to run it, it says
"run time error 13:
type mismatch"

and highlights the if function line...

Please if anyone can tell me what i am doing wrong it will be of great value to me!!:confused:

VBA to un-filter top row/date from table which is auto-filtered? Or some other solution?

$
0
0
Hi all,

I have a particular problem I'm trying to solve and I'm a bit stuck. Basically, I have a macro which copies selected columns (A:O) from a filtered table (let's call it main sheet) to a new sheet.

The problem I'm facing is that often I want to exclude the top row of the table when copying from main sheet to new sheet.

I wrote a macro which simply deletes the top row in the 'new sheet' I copy to, but that messes with the calculations on that new sheet somehow (giving me a lot of #REFs).

I now consider two other solutions:

1) Re-write the macro which copies data such that the top row is always excluded.


This is less desirable as I would like to use the top row at other times. Of course, I could consider using two macros. One for full copy. One for exclude top row.

2) Write/obtain a macro which excludes/unfilters the first row/date of my filtered table in main sheet.


Could anyone give me any pointers on how to proceed with this one?

I suppose the macro would have to select the desired date/cell and then click/run to unfilter.

Or any other advice?

I suppose hiding the row could work as well. But then I'd have to find a quick way to unhide.

Thanks very much in advance.

Attaching a very simple pre-filtered sheet to illustrate. Also - a picture.

Best regards,

Elijah

2.png
Attached Files

Need help figuring out why macro is not attaching the new PDF to Outlook

$
0
0
Disclaimer: I'm new to Macros, so please be kind.

I have a Macro that does the following: Based on an existing excel worksheet, it looks at the Active worksheet, uses a drop down list for a particular dealer code, and changes the information on the active worksheet. it then generates a PDF and saves it to a location on my computer that was designated when it asked for the location to place the file. The issue with the Macro is it Does nearly everything correct, except for attaching the newly created PDF to the outlook message opened. In the excel file, it's pulling information to even capture the applicable email address which to email the file. It's current "displaying" before sending as I work to complete it. Again, the only step it's not doing is to actually attach the newly created PDF Files that were converted from Excel.

Here's the Code:

Code:

Sub DashboardToPDF()
Dim FolderName As String, Fname As String
Dim inputRange As Range, r As Range, c As Range
Dim EmailSubject As String, EmailSignature As String
Dim DestFolder As String, PDFFile As String
Dim Email_To As String, Email_CC As String, Email_BCC As String
Dim OpenPDFAfterCreating As Boolean, AlwaysOverwritePDF As Boolean, DisplayEmail As Boolean
Dim OverwritePDF As VbMsgBoxResult

Application.ScreenUpdating = False
'''' Open file dialog and choose folder
With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    If .Show = True Then
        FolderName = .SelectedItems(1) & "\"
    Else
        Exit Sub
    End If
End With

'''' Location of DataValidation cell
Set r = Worksheets("Dashboard").Range("C1")
'''' Get DataValidation values
Set inputRange = Evaluate(r.Validation.Formula1)

'''' Loop through DataValidation list
For Each c In inputRange
    r.Value = c.Value
    Fname = c.Value
    '''' Save as pdf
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FolderName & Fname, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

'Working in Office 2000-2010
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
 
    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "Cell A1 is changed" & vbNewLine & _
              "The Excel Data is attached in PDF Format" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"

    On Error Resume Next
    With OutMail
        .To = Range("a28").Value
        .CC = ""
        .BCC = ""
        .Subject = "Collision & Mechanical PSX Sales"
        .Body = strbody
'''''this is area of code where I believe an .Attachment.Addxxxxx code goes*** i th
       
        .Display                    'or use .Send
       
           
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

Next c
Application.ScreenUpdating = True


End Sub

[SOLVED] Project Window Folders

$
0
0
I found this on the web:

"... If you click the + icon next to the VBA Project, you will see that there is a folder with Microsoft Excel objects. There can also be folders for forms, class modules, and standard modules. Each folder includes one or more individual components."

I see all my project components like worksheets, modules and forms but I do not see the folders that contain these objects (i.e., Microsoft Excel objects, Forms, Modules). Is there a setting for this?

Running Excel 2010. Windows 7.

Thanks.

Search for more cells in a different sheet and copy another info in the current worksheet

$
0
0
Hello,

First of all, thank you for your help.
I tried to find some codes for my problem, but i didn´t found the right one and i wasn´t able to change them.

I have 500 numbers in an document. It is called ''Idea'' and the sheet is calld TUL.
The numbers are in colume F.
The macro should search in another document(Tosearch) with also 500 numbers on one sheet (Current Week), if it´s on this list. In this document the number is in column G.
If the number is on it, the macro should copy column Z from the same row in the document with the searched numbers in column P.

I have some macro, but it was only working for one searched word, but not for different words.
Can you please help me with this problem.

Thank you very much.

Combine two automated solvers that run in feedback loops

$
0
0
Hi. I'm new to excel vba. My excel model has two automated solvers: Solver A and Solver B that run in feedback loop. Solver A produces an output (a price set at objective npv=0) to be used by Solver B (produce volume at objective npv=0). Solver B will send an input back to Solver A and Solver A needs to solve again until both solvers converge to their respective objectives.

I can simply keep clicking both solver buttons until both converge but it can be up to 10 iterations or more which is tedious and silly. How to combine the two solvers into just one automated solver while meeting both objectives? Appreciate a bit of detailed guide since I am a beginner to vba. Thank you very much!

Get children of members

$
0
0
I have a list of people, some are members, some are not, and some are children of members (also not members).

I need to get all children of each member and concatenate them into a cell (Children in column E). Obviously, husbands and wives will often have the same children.

My fields:

First Name.......Child.......Membership.......Household ID.......Children
Bob...................FALSE.....Member.........1234567............Larry, Cindy
Larry.................TRUE...........................1234567
Amanda.............FALSE.....Member........1234567.............Larry, Cindy
Karl...................FALSE.........................7654321
Cindy.................TRUE..........................1234567


I have attached a parsed down file with an "Actual" and "Desired" look. Mind you, we have many more people than I show.

Note:
All members will have Household ID. Some of the older entries did not.
The membership column may say "Visitor" or "Non Member" or just be blank.
There can be up to two adults in any household.
I don't need children of non members, but if it is easier to figure, that is fine.
Not all columns are shown.

I thought about using an array with the Household ID as a dimension, but there are nearly a million integers (not a million actual households). Honestly, if I just had some direction on how to approach this it would be very helpful.
Attached Files

Pop-Up form or Text file

$
0
0
Hi,
Hope I might explain my query here. I want to make a button for details in a sheet and when user click that button a pop-up window or form opens. In this case I need details for the user and which also needs to be updated as well.

User Defined Function for last row or column in worksheet

$
0
0
Hi,

I found a function that determines the last row or column in a worksheet at the spreadsheet guru website.

However, when I tried the function it did not work.

I suspect that I am not entering the function properly, see the attached workbook at my attempts.

Any help much appreciated, thanks John
Attached Files

change the colour format of a combo box?

$
0
0
Hi.

I have created a combo box so i can have a drop downlist. Is it possible to change the colour of the dropdown list so it doesnt stand out so much on the page?

enter X with data validation

$
0
0
Hello to all.
In the attached workbook in column D3 onwards there is a value (minutes)
I think it is accurate with a data validation combined with a macro.
It should work like this:

now in D3 there is 25.00 (minutes) in the drop-down menu I choose "6FDLDL88" letter X must be inserted in K3
now in D5 there is 204.00 (minutes) in the drop-down menu I choose "11HFLLFLF11" the letter X must be inserted in P5
now in D7 there is 51.00 (minutes) in the drop-down menu I choose "5EASDE55" the letter must be inserted in J7

and so on up to line 60000
I hope I explained myself.
xam
Attached Files

Capture "cancel" on Standard Menu " close "

$
0
0
Windows 10 running Excel 2003.

I need to capture the cancel event when the "Cancel" button on the standard Menu/Close form is pressed.

I'm using Menu/Close to exit a workbook (which contains VBA code) , and the "Yes" and "No" buttons work fine.
However, the "Cancel" button isn't taking me back to the workbook's condition prevailing before it was pressed.

So I need to capture it's event to see where it actually occurs in my code.

Web trawls have produced nothing of use.

how to filter combobox value based on another combobox

Viewing all 49875 articles
Browse latest View live