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

Vlookup - Value in one page, Range in another page

$
0
0
I want to send email to :
Code:

.To="email123456@yahoo.com"
I have Name in Sheet1 cell G3
In Sheet2 I have Range B2:C50 (B contain Name, C contain email)

I want to replace "email123456@yahoo.com" with Vlookup(Sheet1 G3, Sheet2 B2:C50, 0)

Automatically save complete workbook, without formulas, to a new location

$
0
0
Hi,

Many months ago at work I started creating an Excel document, which over the months grew and grew into a huge beast laden with all kinds of excel formula's.

Over time, my (not so ICT adept) colleagues started seeing the benefits of all the data within the file and many of them are now consulting it on a daily basis. My colleagues don't need the formula's and never change anything, they just consult it.

Also, when they currently open the document, it takes between 30 and 90 seconds just to load because of all the calculations within.

So I was thinking: Wouldn't it be nice to have a button to save the document to a specific location (shared location where my coworkers usually find it); and that the saved file is data + formatting only?

Could this be achieved with a custom button or hotkey launching a VBA application? I know some VBA, but not nearly enough to quickly figure this out on my own.

Anyone willing to help? I would be most grateful! :)

Thanks in advance!

Add Row, Renumber Summary Table

$
0
0
I have a workbook where there is a summary table containing a fixed number of rows (in my example, 10 rows).

I want to a macro that will allow me to (1) add a row to the left of the summary table (2) after inserting the row in step #1, redo the summary table so that it is still contiguous set of 10 rows . So goal = insert row running through a table, then make the data inside that table once again contiguous.
Attached Files

problem .find

$
0
0
Good afternoon everyone,

i have a workbook with 13 worksheets ( 1 per each month and one recap). I am trying to look for the value of "No fiche chantier" - column D) in every worksheets (except "impayes" - index 13), then if it's found in the worksheet x and that the column "o" is NOT empty, then delete relevant row from the worksheet "impayes".

Ex: 1. in the worksheet impayes row nr 5, take the value of column D = 18332

2. look for "18332" in all worksheets from "janvier" to "dec" (but NOT in "impayes")

3. if found in worksheet (in this example, "18332" does not exist in january, so jump to February, then found it), and in this worksheet the relevant row, column "o" is not empty

4 if 3 is true then delete relevant row from "impayes

Basically "impayes" repeats all the rows of all the other worksheets, but i want to keep only the row where the column O is empty.

Here is my code which is not working, it look first in "impayes" instead of excluding it:


Code:

Private Sub Worksheet_Change(ByVal Target As Range)


Dim i As Long, irow As Long, r As Range, ws As Worksheet, sfilter As String


'pour chaque ligne de la feuille ("impayes") a partir de la ligne 5 jusqu'a la derniere ligne ou la colonne B est vide


  For i = 5 To Range("B" & Rows.Count).End(xlUp).Row
 
  ' sfilter = No fiche chantier (colonne D)
   
        sfilter = Cells(i, "d")
 
      For Each ws In ThisWorkbook.Worksheets
     
      If ws.Index <> 13 Then
       
    ws.Activate
   
irow = ws.Cells.Find(What:=sfilter, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Row
       
   
                            If Cells(irow, "o") <> 0 Then
                            Rows(i).EntireRow.Delete
                            End If
        End If
       
  Next ws
 
  Next i
   
End Sub

Pulling images into a report from another Tab

$
0
0
Hi All!

Wondering if there is a way to insert an image from one tab to another?

Tab 1 = You'd be able to select you're account from a drop down which would generate the order data they placed. I'd like the image to be included for each style they ordered. Just not sure how to pull that info or if it can even happen due to drop down.

Tab 2 would be an inventory listing with image so it would have Season | Style # | Style name | Color (each in their own cell to which I could concatenate together). From this list you would get the image for it's own cell which matches.


Help :)

Extract/Generate Data through VBA based on period basis from master data sheet

$
0
0
Hi,

I have an excel file named product master in which I want to extract a price list based on Date Selection. As you click on the blue cell in Price List sheet a calendar will be applied and as you select the date the price list generates for that date. The period selection process is based on a calendar basis as we select to two date dates price list will be extracted or generated automatically (Product List_Period Sheet). Currently, It is taking time because it is based on excel formulas based. Now, I want to make it advance through VBA coding. I have tried on my own but I am not able to make this as I don't know advanced VBA coding. Please help with this if any VBA expert has sufficient time. I will be very thankful to him/ her. Thanks in advance.

[SOLVED] Output dictionary items to an email body

$
0
0
Hello all,

I have the following code where I create a dictionary to store data from a sheet based on certain conditions, if one of the columns is =< 3, I store certain Columns of that row to my dictionary.

I then need to send an email, and the body of that email needs to be all the items from my dictionary, I am stuck at this part and cannot figure out how to output the items of my dictionary to the body of the email.

I need help with this part: .Body = dic(str) clearly this is not the right syntax to do that....

can someone pls help me. :)

Many thanks

Code:

Sub open_position_email()

Dim i As Integer, x As Integer, lcol As Integer, nb_orders As Integer
Dim dataWS As Worksheet, mainWS As Worksheet
Dim lastColumn As Integer
Dim LR As Integer
Dim i_text As Variant
Dim dic
Dim str As String
Set dic = CreateObject("scripting.dictionary")


Application.DisplayAlerts = False
Set dataWS = Sheets("Sheet1")
Set mainWS = Sheets("Open_Data")

lcol = 15
LR = dataWS.Cells(Rows.Count, 1).End(xlUp).Row
Cells(4, lcol).Select

'inputing a formula to determine how many days away this order is
Selection.Value = "Days Away"

With dataWS.Range(Cells(6, lcol), Cells(LR, lcol))
    .FormulaR1C1 = "=RC[-5]-TODAY()"
    .Value = .Value
End With

'' store in dictionary values of row with less than 3 days away from formula
For i = 6 To LR
If Cells(i, lcol).Value <= 3 Then
   
    'str = Cells(i, 1) & "_" & Cells(i, 2) & "_" & Cells(i, 5) & "_" & Cells(i, 6) & "_" & Cells(i, 7) & "_" & Cells(i, 8) & "_" & Cells(i, 11) & "_" & Cells(i, 19)
    If Cells(i, 7) > 0 Then
        str = dataWS.Cells(i, 3) & " " & dataWS.Cells(i, 1) & dataWS.Cells(i, 2) & " debit" & dataWS.Cells(i, 7) & " contracts " & dataWS.Cells(i, 4) & " -- Order Delivery Day " & dataWS.Cells(i, lcol) & "days away"
        Else
        str = dataWS.Cells(i, 3) & " " & dataWS.Cells(i, 1) & dataWS.Cells(i, 2) & " credit" & dataWS.Cells(i, 8) & " contracts " & dataWS.Cells(i, 4) & " -- Order Delivery Day " & Cells(i, lcol) & "days away"
    End If
      If Not dic.exists(str) Then dic.Add str, i
  nb_orders = nb_orders + 1
End If
Next i

'' with dictionary created, I want to send an outlook email with the body being all my dictionary items
Dim OutApp As Object
Dim OutMail As Object
Dim SubjectName As String

With Application
        .EnableEvents = False
        .ScreenUpdating = False
End With

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

SubjectName = "Orders less than 3 days! - " & Format(Now(), "dd-mmm-yy")

  On Error Resume Next
    With OutMail
        .To = "name@company.com; name@company.com"
        .CC = ""
        .BCC = ""
        .Subject = SubjectName
        .Body = dic(str)
        '.HTMLBody = RangetoHTML(dic)
        .Display  'or use .Send
    End With
    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing

Still not able to make userform show up runtime error


VBA saveas sheet to webpage (html) is also creating blank workbooks

$
0
0
hi,

I am using excel vba to create a html page for a particular sheet, every time i run the vba, before converting to html, vba is creating a new workbook with that sheet and then converting,

if it is the process please help me to close that workbook without saving in the background only.

code i am using

Application.Sheets("Index").Activate
ActiveSheet.Copy
Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Users\klrag\Desktop\DPR website\DPR.html", AccessMode:=xlExclusive, ConflictResolution:=Excel.XlSaveConflictResolution.xlLocalSessionChanges, FileFormat:=xlHtml
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.EnableEvents = True

thanks in advance

Error:Wordeditor runtime error 287

$
0
0
I have a macro code which helps to split the data and and draft the mail in outlook..unfortunately im getting error message in " Set wEditor = vInspector.WordEditor" in this part ..Can someone look into this ?

This macro contains 3 module. For reference below is the one module which helps to draft the mail. There is something wrong in wordeditor part as am getting error as runtime error 287 . Is there any other way to paste the range as picture ? Appreciate your help.


Code:

Public Sub sendEmail(path, personName As String)


 
  Dim book As Workbook
  Set book = Workbooks.Open(path)
 
 
    Dim Sht As Excel.Worksheet
    Set Sht = book.Sheets("Summary")
   
    Dim ShtLogo As Excel.Worksheet
    Set ShtLogo = book.Sheets("Logo")

    Dim rng As Range
    Set rng = Sht.Range("C5:I39")
        rng.Copy
       
       
 

    Dim OutApp As Object
    Set OutApp = CreateObject("Outlook.Application")
   
   
   

    Dim OutMail As Object
    Set OutMail = OutApp.CreateItem(0)
   
    OutMail.Display

    Dim vInspector As Object
    Set vInspector = OutMail.GetInspector

    Dim wEditor As Object
    Set wEditor = vInspector.WordEditor

    With OutMail
       
        .To = ""
        .CC = ""
        .Subject = ""
        .Attachments.Add path
        .Display
     

      wEditor.Paragraphs(1).Range.Text = "Dear " & personName & Chr(11) & "Below is a snapshot of the inventory movement last week(details in the attached),relating to your Engagement Portfolio." & vbCr

        wEditor.Paragraphs(2).Range.Paste
       
       
   
       
    .Save
    '.Close
       
       



    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
   
    book.Save
    book.Close
   
   
 
End Sub

Send e-mail - filter date range & customer name

$
0
0
Evening All

With the attached worksheet I am trying to e-mail the customer a weekly acknowledgement e-mail of the submissions they sent last week (Monday-Sunday) and submissions which have been completed.

I have two issues:

- The code e-mails every customer, even if they didn't send or have completed any work last week. I'm guessing I need to alter the below?

Code:

OrigList = ""
    For Each C1 In OrigRng
        If Not OrigList Like "*" & C1 & "*" Then
            If Len(OrigList) > 0 Then OrigList = OrigList & ","
            OrigList = OrigList & C1
        End If
    Next C1
   
    Origs = Split(OrigList, ",")

- Secondly, I cannot get the code to pick up the date range in Column D. If I change the format to number type no problem but in Date format the e-mails all appear blank. Any ideas please?

Code:

If ProjData(6) >= CDbl(LW3) And _
        ProjData(6) <= CDbl(LW1) Then
            If Len(RecBullets) = 0 Then RecBullets = "<b><u>SUBMISSION RECEIVED</b></u><ul>"
            RecBullets = RecBullets & "<li>" & ProjData(1) & " - " & ProjData(9) & ": " & ProjData(9) & "</li>"
        End If
     
        If InStr(ProjData(2), "Completed") > 0 And _
        ProjData(3) >= CDbl(LW3) And _
        ProjData(3) <= CDbl(LW1) Then
            If Len(CompBullets) = 0 Then CompBullets = "<b><u>SUBMISSIONS COMPLETED</b></u><ul>"
            CompBullets = CompBullets & "<li>" & ProjData(1) & " - " & ProjData(5) & ": " & ProjData(9) & "</li>"
        End If



Many thanks!
Attached Files

Formula in and offset cell based on location of text

$
0
0
Hi all, you solved a problem yesterday in no time, so here is another simple one.

I have Columns A & B, the length of which will vary, but the last value in Column A will be 'Grand Total', adjacent to which is, you guessed it, a sum of the values in Row B. This has come from a subtotal function, but is now just text after a copy and paste.

What I want to do is create a formula in the offset cell 0,2 relative to Grand Total. If Grand Total was in Cell A5, the formula would be in C5 "=B5=Sheet1!N55"

It is to check to total matches that from the original sheet after formatting. If TRUE, it would be great if I could return specific text instead of TRUE.

Hopefully this all makes sense!

detect the smallest with the highest number in each sector, forming two pairs

NUmber search

$
0
0
Hi,
I am currently using instr search to find the text.
In the same way, i want to search numbers.. when the user types 5 number and search button is clicked, then the matching numbers must be populated in listbox.
How to go about number search.
instr is for string?

Print Preview of a Temporary Workbook

$
0
0
Hey guys, so I'm having a little trouble with the print preview of my temporary workbook. My current code is set up to:

1) Copy data from my workbook to a temp workbook
2) Print the temp workbook
3) Close the temp workbook without saving

I would like to add a print preview before printing (not allowing changes). The problem I'm running into is what happens if the user sees that the report is wrong and wants to cancel the print by clicking cancel or the "X" on the print preview screen.

If the user selects cancel I would like for the code to:

1) Close the temp workbook without saving
2) Return to my main workbook
3) Turn screen updating back on


I have listed my current code below, along with a sample workbook. Any help is appreciated!!

Code:

Private Sub CommandButton1_Click()
Dim Worksheet As Worksheet
Dim xrgvlist As Range
Dim z As Long
Dim temp As String
Dim main As String
Dim T As Long
Dim pctdone As Double
    Set Worksheet = Worksheets("CARD")

   
    If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
   
Application.ScreenUpdating = False

    Set progressindicator = New UserForm2
    progressindicator.Show vbModeless
   
    If TypeName(ActiveSheet) <> "Worksheet" Then
        Unload progressindicator
        Exit Sub
    End If
   

With Worksheet
    Set xrgvlist = Evaluate(.Range("B1").Validation.Formula1)
    main = ActiveWorkbook.name
       
    T = xrgvlist.Cells.Count
        For z = 1 To Application.Min(xrgvlist.Cells.Count)
            Windows(main).Activate
            .Range("B1") = xrgvlist(z).Value
           
        Select Case z
       
            Case Is = 1:
                Worksheets("CARD").Copy
                temp = ActiveWorkbook.name
               
            Case Is <> 1:
                Worksheets("CARD").Copy after:=Workbooks(temp).Sheets(z - 1)
        End Select
       
        pctdone = (z) / T
                With progressindicator
                    .Label1.Caption = "Building Card " & (z) & " of " & T
                    .FrameProgress.Caption = Format(pctdone, "0%")
                    .LabelProgress.Width = pctdone * (.FrameProgress.Width - 10)
                End With
   
                DoEvents
       
        Next z

        Unload progressindicator
            Set progressindicator = Nothing
           
       
               
'        Workbooks(temp).PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
'        Workbooks(temp).Close savechanges:=False
'
   
End With
Application.ScreenUpdating = True

End Sub

Attached Files

Type Mismatch for Set myArr = Array(...)

$
0
0
I am trying to assign the values like "<1", "5", etc to an array. Need to use these values in a loop to be assigned to a cell for Adv FilterCopy criteria.

Code:

Dim myArr
'.....
'... some code

myArr = Array("Taxable Amount", "Tax Type", "VAT Amount", "GST Rate", "CGST Amount", "SGST Amount", _
                          "IGST Amount", "Cess Amount", "Fixed Cess Amount")

'... some code...

Set myArr = Nothing
Set myArr = Array("<1", "5", "12", "18", ">27")  'this line gives Type Mismatch error

... some code

I am using myArr repeatedly for diff purpose during the code of this Sub. Earlier in the code I have used similar line and it works just fine. I even tried changing the values to "aa<1", "aa5", "aa12", and so on. I tried it in case the values "<1" look like an expression. But it did not work either.

pls guide me.

VBA C_Paste range from one wbks with multiple ws to multiple wbks and multiple ws

$
0
0
Hi,
There are 4 workbooks names as “Branch1-Mar 2020.xlsm”, “Branch2-Mar 2020.xlsm”, “Master File-Mar 2020.xlsm” and “VBA macro.xlsm”. Workbook name “VBA macro” were macro has been written in module1.

1. Sheets named “USA” are veryhidden in workbooks name Branch1, Branch2, were amount are clubbed
2. Masterfile workbook having monthly data with sheet name Branch1, Branch2
3. MonthEnd date will change each month
4. There are 15 branches, cannot create 15 macros –only 2 braches considered for below example

Error are as below
1. Macro open “Master File-Mar 2020” workbook, but cannot open “Branch1-Mar 2020” workbook
2. Is it possible Loop can paste data in multiple workbooks with multiple worksheets with 1 macro
3. below code only transaction for 1 branches,


Sub MIS_TransferBranch1()

On Error Resume Next

'Code for transfer from "Master File-Mar 2020" to "Branch1-Mar 2020" workbooks
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False

Dim Wkb1 As Workbook
Dim Wkb2 As Workbook
Dim rngToCopy As Range
Dim rngToPaste As Range
Dim Month As Integer

'Month end date, its changes every month "B18" contains month end date "Mar 2020"
Month = Sheets("Tool").Range("B18").Value

' set the workbook you are copying to as active and give it a name for reference (data are for month)"B9" is path "B10" if file name
Set Wkb1 = Workbooks.Open(Filename:=Sheets("Tool").Range("B9").Value & "\" & Sheets("Tool").Range("B10").Value)

' open the workbook you are copying from and activate it (data are cumulative)"B15" is path "B16" if file name
Set Wkb2 = Workbooks.Open(Filename:=Sheets("Tool").Range("B15").Value & "\" & Sheets("Tool").Range("B16").Value)

Wkb1.Activate
With Worksheets("Branch1")
Set rngToCopy = .Range("A1", "D1200") 'data need to copy cells
End With


Wkb2.Activate
Worksheets("USA").Visible = xlSheetVisible ' sheet is veryhidden, need to visible
Worksheets("USA").Activate
With rngToCopy
Set rngToPaste = Worksheets("USA").Range("A1:D1200") ' data need to paste cells
End With
rngToPaste.Value = rngToCopy.Value
Application.CutCopyMode = False
Worksheets("USA").Visible = xlVeryHidden
Workbooks("Branch1-" & "Month" & ".xlsm").Save ' data pastespecial to workbook saved
Workbooks("Branch1-" & "Month" & ".xlsm").Close True ' closed wks

MsgBox "Uploaded"
End Sub

List manipulation, how to change the starting point in a list of set numbers

$
0
0
Hello,

Ive spent hours trying to look up formulas to help me change the start point of a set list of numbers. Using Roulette wheel as an example. 0,32,15,19,4..... would be placed 0,1,2,3,4,5 in a clockwise spin. So if 15 came in i would want to insert 15 and the list would reconfigure and start 15 as 0, 19 as 1, 4 as 3.....etc. 0 and 32 at the begining of the list would be moved to the bottom in the same order as the wheel, does that make sense? Essentially i am treating the last number coming in as home and looking for patterns in how many places from home the ball drops.

Macro to Email set of cells with identified email list and subject line with outlook

$
0
0
I am looking for some help with a macro to email the group of cells B2:K20 pasted in the body of the email via outlook.
I will have the email list identified N2:N15
The subject line will be cell O2

Email will be sent via outlook

Any help with making this macro would be greatly appreciated.

I have attached a blank file with the section identified that will be used for the email.
Attached Files

Copy paste code required

$
0
0
Hello Everyone,

Please find the attached sample sheets in which i require a VBA code to copy paste data as per below requirement

currently How i copy and paste right now is:
1- first i copy and paste from location to contact person in a new sheet then
2 -copy and paste 16th mar 20 whole column data against the above (point 1), so that i can get project names against employee names, location and etc.
3 - then i again repeat point 1 and filter non blanks from 1st additional project names which is next to 16th march date column (Yellow highlighted) and i paste it then i remove filter from yellow column and repeat point 1 and filter non blank in additional project names (this time its red)
4 - then again i remove filter from everything and repeat from point 1 to point 4 for 17th March date
5 - i have do this for whole month, but i get data weekly.

Important point is wherever date is mentioned should be copy and pasted with blanks and additional projects names should be copy and pasted without blanks.

Any help would be appreciated..
Attached Files
Viewing all 50040 articles
Browse latest View live