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

User form functİon problem

$
0
0

İ HAVE A USER FORM WHİCH TAKES SOME DATA FROM THE EXCEL SHEETS AND
İ WANT İT TO MAKE SOME CALCUATİONS. İTS OK ALL TO THE END WİTH THE BELOW CODE.
BUT İT DOESNT CALCULATE THE LAT TWO COLUMNS.
İN FACT WHEN İ TAKE OUT THE DPTXT.VALUE AND WRİTE SOMETHİNG ELSE İTS OK BUT
AND THEN EVEN THE LAST CALCULATİON WORKS.

Code:

Private Sub yeni_Click()
 'Set some Workbook variables:

Set book1 = Workbooks("EGEARGEsontest3.xls")
Set srchRange = book1.Sheets("ARGE").Range("c1:Bp65000")
Set srchRange2 = book1.Sheets("iplikson").Range("b1:h1500")
'€/$ paritesi
parite = Workbooks("EGEARGEsontest3.xls").Sheets("iplikson").Range("k1").Value
'€ fiyatı
parite2 = Workbooks("EGEARGEsontest3.xls").Sheets("iplikson").Range("k3").Value
r1 = WorksheetFunction.VLookup(bctxt, srchRange, 36, False)
r2 = WorksheetFunction.VLookup(bctxt, srchRange, 41, False)
r3 = WorksheetFunction.VLookup(bctxt, srchRange, 46, False)
r4 = WorksheetFunction.VLookup(bctxt, srchRange, 51, False)
r5 = WorksheetFunction.VLookup(bctxt, srchRange, 15, False)
'base kodun altına gelecek olan kumaş tanımı
Description = r1 & " " & r2 & " " & r3 & " " & r4 & " " & r5 & " " & r12
'r6 is gramaj:
R6 = WorksheetFunction.VLookup(bctxt, srchRange, 27, False)
'r7 is en
R7 = WorksheetFunction.VLookup(bctxt, srchRange, 29, False)
'r8 is knit price
r8 = WorksheetFunction.VLookup(bctxt, srchRange, 56, False)
'r9,10,11 are the yarn percentages
r9 = WorksheetFunction.VLookup(bctxt, srchRange, 35, False)
r10 = WorksheetFunction.VLookup(bctxt, srchRange, 40, False)
r11 = WorksheetFunction.VLookup(bctxt, srchRange, 45, False)
'r12 kumaşın ingilizce adı
r12 = WorksheetFunction.VLookup(bctxt, srchRange, 53, False)
'boya fiyatı
R13 = WorksheetFunction.VLookup(bctxt.Value, srchRange, 57, False)
' fire oranı
R14 = WorksheetFunction.VLookup(bctxt, srchRange, 59, False)
'ham kumaş fiyatı varsa
r19 = WorksheetFunction.VLookup(bctxt, srchRange, 62, False)
'ham kumaş ın fiyatının para birimi
r20 = WorksheetFunction.VLookup(bctxt, srchRange, 63, False)
'mamulkumaş fiyatı varsa
r21 = WorksheetFunction.VLookup(bctxt, srchRange, 60, False)
'mamul kumaş ın fiyatının para birimi
r22 = WorksheetFunction.VLookup(bctxt, srchRange, 61, False)
'mamul alınacak ise
R23 = WorksheetFunction.VLookup(bctxt, srchRange, 58, False)
' İPLİK FİYATLARI

P1 = WorksheetFunction.VLookup(r1, srchRange2, 7, False)
P2 = WorksheetFunction.VLookup(r2, srchRange2, 7, False)
P3 = WorksheetFunction.VLookup(r3, srchRange2, 7, False)


DESTXT.Value = Description
YARN1TXT.Value = r1
Y1PTXT.Value = P1
YARN2TXT.Value = r2
Y2PTXT.Value = P2
YARN3TXT.Value = r3
Y3PTXT.Value = P3
PERC1TXT.Value = r9 / 100
PERC2TXT.Value = r10 / 100
PERC3TXT.Value = r11 / 100
KNITPRICETXT.Value = r8
DPTXT.Text = R13
WETXT.Value = R6
WITXT.Value = R7
UWETXT.Value = R7 - 6
LOSSTXT.Value = R14
PROFITTXT.Value = 1.1
COMTXT.Value = 1.05

GPTXT.Value = (Y1PTXT.Value * PERC1TXT.Value * 1.05) + (Y2PTXT.Value * PERC2TXT.Value) * 1.05 + (Y3PTXT.Value * PERC3TXT.Value * 1.05) + KNITPRICETXT.Value
KgpTXT.Value = (GPTXT.Value + DPTXT.Text)
MTPTXT.Value = KgpTXT.Value * (WETXT.Value / 1000) * (WITXT.Value / 100)


VBA to filter the ActiveCell whether it is a Date, Text, Amount, etc

$
0
0
My current VBA code is:

Code:

Sub Filter_by_Active_Cell()
    Dim ColNum As Integer
    ColNum = ActiveCell.Column - (ActiveCell.CurrentRegion.Column - 1)
    Selection.AutoFilter Field:=ColNum, Criteria1:=ActiveCell
End Sub

It works fine unless the ActiveCell is a Date ... then NO results are returned.

How can I modify this code so that whether the Activecell is an amount, text, date, etc, it will filter properly?

Your help will be appreciated.

Thank you.

VBA Looping for copy paste after running analysis

$
0
0
Hello,

I need some help with the following VBA. I was unable to get a loop to reliably run my analysis, and thought it may be easier for someone to look at the steps I need repeated. I have locked in specific cells that cannot change, and anything unlocked will need to copy/paste from the row below. I will need this to continue this loop until the dates from the Range B8-B1500 end (Output Tab). Thanks for your help--see below.

Sub Runner()

'Change Date

Worksheets("Output").Activate
Range("B8").Select
Selection.Copy

Worksheets("Analysis").Activate
Range("$C$10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

'Copy and Paste Outputs From Analysis Tab to Outputs Tab

Range("$G$6").Select
Selection.Copy

Worksheets("Output").Activate
Range("D8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Worksheets("Analysis").Activate
Range("$G$7").Select
Selection.Copy

Worksheets("Output").Activate
Range("E8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Worksheets("Analysis").Activate
Range("$G$17").Select
Selection.Copy

Worksheets("Output").Activate
Range("F8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Worksheets("Analysis").Activate
Range("$H$6").Select
Selection.Copy

Worksheets("Output").Activate
Range("G8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Worksheets("Analysis").Activate
Range("$H$7").Select
Selection.Copy

Worksheets("Output").Activate
Range("H8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Worksheets("Analysis").Activate
Range("$H$17").Select
Selection.Copy

Worksheets("Output").Activate
Range("I8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

'This is will be repeated until there are no more dates

End Sub

Intermittent error with email generation macro - pasting from excel to outlook mail

$
0
0
I have a macro that pastes a range into an email it generates. It works great, but not every time. Sometimes I get a runtime error 91: Object Variable or With Block Variable not Set. This usually occurs when I've restarted my computer, reopen the workbook, or just let the workbook sit for a while. If I hit End on the error and try again, it works perfectly.

Another problem is that it will paste into any email draft I have already open instead of the one it opens. This isn't a fatal flaw for the application, but I wonder if the previous problem isn't related to this. Could making the email that it creates become the "active" item solve both problems? How is this done?

The line that is highlighted by debugging is the paste line. Although I swear it has highlighted other lines before as well. I've played around with this a lot and I haven't been able to narrow down why the problem is so intermittent.
Code:

Sub CopyAndPasteToMailBody()

ActiveSheet.Unprotect "Password"

    Set mailApp = CreateObject("Outlook.Application")
    Set mail = mailApp.CreateItem(olMailItem)
    mail.Display
    Set wEditor = mailApp.ActiveInspector.wordEditor
    ActiveSheet.Range("A1:I36").Copy
    wEditor.Application.Selection.Paste
   
    With ActiveSheet
    .Protect Password:="Password", AllowFiltering:=True, AllowSorting:=True
    .EnableSelection = xlUnlockedCells
    End With

    With mail
        .Subject = "Subject" & Format(Date, " mm/dd/yy")
        .To = "email
        .CC = "email
        '.Send  'Change to send without viewing
    End With
End Sub

comparing two sheets of data

$
0
0
Hi All,

Not sure if this should be in VBA or Formulas however what im trying to achieve:

I have a data report that i pull today, tomorrow i want to run the same report and see if there are any differences on the report. e.g show data that was not on the previous report.

Id imagine id have a sheet with yesterdays data, sheet with todays data, sheet with Differences that only shows the new lines between the report. Then after i have done i would just create a macro clear the difference sheet so its blank, copy todays data over to yesterdays data and repeat the process daily.

What is the easiest way to do this? im getting stuck on the comparing..

VBA with vlookup across multiple worksheets

$
0
0
I have multiple worksheets with data for which I would like to write a macro to search and "retrieve" based on the State/County/Municipality and Client selected. I have created the drop down menus that should drive the data being searched, but I'm not confident in my very limited abilities to take this to the next level.

End goal: User should be able to select from the dependent drop down lists (State/County/Municipality) and/or Client, click "Retrieve Data" button and pull in data from the appropriate worksheet driven by the selection in the drop down lists.
Attached Files

Start a file with a series of entry boxes...

$
0
0
The 2nd half of this code is written and working, now I just need help with the 1st half. Here's what I'd like to do.

1. We have a file, called ABC.xlsm, which we use as a template.
2. A worker would open an excel file - this file might be ABC.xlsm itself, or if per your advice it's better, a different file which contains or links to ABC.xlsm.
3. Immediately upon opening that file, an entry box comes up on the screen (only this box is visible, the contents of the Excel file are not yet visible) the box contains a question and a blank field for an answer to that question. That answer will populate cell A1 of Sheet1 of ABC.xlsm, as well as become part of the new file name.
4. After entering the answer to the first question and clicking OK, 5 more successive entry boxes each with one question will be presented to the user, one at a time. The answers to those questions will populate cells A2-A6 on Sheet1 of ABC.xlsm, as well as become part of the new file name.
5. After the 6th entry box is filled out and OK is selected, ABC.xlsm will be saved to a specific location, with a new file name, based on the entries.
6. The newly named file is opened and presented to the user and they can proceed with further inputs, then save and email to other users.

I've already accomplished steps 5 and 6 - currently the user simply opens ABC.xlsm, manually fills in cells A1-A6, then clicks a button in the spreadsheet which runs the following code:

Code:

Sub SaveMyWorkbook()

    Dim strPath As String
    Dim strFolderPath As String

    strFolderPath = "http://fll.abc.com/sites/RRRMatls/full/Administration/"

    strPath = strFolderPath & _
        Sheet1.Range("F1").Value & ".xlsm"

    ActiveWorkbook.SaveAs Filename:=strPath
   
    ActiveSheet.Shapes("Button 14").Delete
   
End Sub

Cell F1 in the above is a concatenated string based on the inputs of cells A1-A6.

So steps 1 through 4 are what I need help/guidance/suggestions with accomplishing. I also have Visual Studio 2010, if perhaps it's suggested to be easier to do this in there, and create an exe. program to be run, as opposed to starting with an Excel file. In either case, I just have no idea where to start with the code for Steps 1 through 4.

Thanks so much in advance.

pastespecial doesn't include objects, but paste (non-special) does

$
0
0
I have a fairly simple macro that copies a range of cells from one sheet and pastes them to another sheet in the first blank row. one or more of the original cells could contain inserted objects (for example, a microsoft Word icon - Insert > Object > Word Doc > Display as icon). My macro won't copy over the inserted object and I found through manual recording of macros that the non-special paste command (Ctrl-V or right-click Paste) does paste objects, but pastespecial does not include copied objects. Any ideas as to how to include objects in the paste?

Code:

Private Sub OKCommandButton1_Click()

Dim NextRow As Range
    With Sheets("Complete")
        Set NextRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
    End With
    Sheets("Active").Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 27)).Copy
    NextRow.Paste Special Paste:=xlPasteAll Transpose:=False
    Application.CutCopyMode = False

Sheets("Active").Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 27)).Delete Shift:=xlUp


MsgBox "Client has been successfully moved."

Unload Me

End Sub


Row deletion trouble

$
0
0
Hi All,
So I have an excel macros tool that adds a row of data to a list and can also delete a row of data from that list. All of a sudden my program has started freezing ("Not Responding") when I try to delete an entire row of data. This even happens when I go in and manually try to delete a row. This issue just started happening and I haven't been able to figure out why. If any one has experienced an issue like this before please shoot me some ideas, I would greatly appreciate it!

crash after worksheet calculate

$
0
0
The situation is a Workbook_Activate macro is conflicting with a worksheet module which is a worksheet_calculate that also runs a macro when there is a query refresh from another book.
How do I get the workbook activate macro to run before the worksheet one activates?
Right now everything crashes.

Return a value from another worksheet based on Cell Name

$
0
0
Hi everyone,

I've been learning some VBA code and am pleased with the progress I've made so far from this website. I've run into a stump that I can't solve and am hoping to get some help!

I have worksheets that are created based on the "WSC ID" (found in the "Data Summary" worksheet). I will have a list of different WSC IDs and there will be as many worksheets as there are WSC IDs.

I would like to get numbers pulled from their respective worksheets. You will see in the attached spreadsheet the values I want returned (labeled in red at the bottom of the worksheets) to their respective row in the "Data Summary" worksheet.

Any help would be great, and my apologies if my wording is confusing.

Thanks!
Attached Files

Submit button Macro not working correctly

$
0
0
Hi all you amazing forumers!!

I've attached a spreadsheet in which a request is entered into a certain area.

This should then jump to a specified place in the view data tab that is relevant. For example, if someone chose inputdata>businessimprovement>openedanewaction then pressed submit then this data would go to the tab 'VIEWBusiness Improvement. If possible showing the date, business improvement and opened a new action?

As there is a lot of data I would like something that I can duplicate with all 17 'Submit' buttons that will be clicked. I have another spreadsheet with this on but cannot transfer it across.

Once the submit button is then pressed the from should revert to empty again and, if possible, the user would get a choice to submit a request in the same place or go back to the last tab they were on to chose another team? I cannot think for the life of me where to start and I will be impressed if someone can do all of the things I've asked for.

Thanks all of you beautiful people, feel free to make changes to the spreadsheet if necessary. I am so grateful to all of you!!! Frank
Attached Files

Copy paste specific row of data based on user input

$
0
0
Hello,

I am new to VBA and I need to copy and paste the specific dates from the specific city that the user will insert in the "dash" sheet.
Basically, I need the macro to read the city and range of dates that the user will type into the "dash" sheet and copy the columns "AA" to "AD" from rows specified by the dates input. Once it has been copied, it has to be special pasted just the value onto the sheet "1" beginning at location B2.

Please note, the the data will not be available as it is vlookups to another excel sheet that i have not provided. I have deleted the data, but you can pretty much put 1's everywhere.

Thank you very much!
Attached Files

Macro to go to webpage and copy page to excel

$
0
0
Hi guys i need help to write a macro to go to an internet page select all then special paste text in sheet 1 a1 .

Links are not Updating manually with '.UpdateLinks' code

$
0
0
Hi Everyone,

So I am trying to automatically update links on Powerpoint, which I have copy and pasted the link via 'Paste Special > LInk'. The code works when I set Powerpoint 'Edit links to File' as Automatic but when I set it to Manual nothing gets updated.

Does anyone know how I can fix this?

Thank you in advance! :)

Code:


Sub Auto_Close()

Application.DisplayAlerts = False

Dim objPPT As Object
   
    Set objPPT = CreateObject("PowerPoint.Application")
    objPPT.Visible = True
    objPPT.Presentations.Open "C:\Users\anneg\Desktop\Presentation1.pptx"
   
   
    On Error GoTo 0
    objPPT.activepresentation.UpdateLinks
    objPPT.activepresentation.SaveAs "C:\Users\anneg\Desktop\Presentation1.pptx"
    objPPT.Quit


    End Sub


How to: Turn Summary Sheet into detailed Sheets (multiple tabs)

$
0
0
I have a summary sheets for my report that my department no longer wants to use. Rather they want to have a longer, more detailed version of the same thing, but rather than 1 sheet summarizing it all, they want it 1 widget, 1 sheet.

How can I have my Checksheet tab (see upload), turned into multiple tabs. In the specific example I provided, there are 10 widgets, so therefore I created the result in 10 tabs.

How can I get a macro to turn Checksheet tab into the next 10 tabs (see excel upload)?

I have attached the excel sheet of how my summary sheet is, and how it's supposed to look like.
Attached Files

Macro to hide rows based on today's date and auto run it

$
0
0
Hi,

I'd like to create a macro that will hide rows based on today's date. I'd like to hide any rows that include dates that are one week old or older. I'd then like the macro to run automatically on opening the workbook. Some dates have passed already. Ideally, the rows with dates that are older than 1 week, would hide automatically when I open Excel.

Sample workbook:
Cells A3:A22 have dates 4/1/14 thru 4/20/14
Cells B3:G22 have other data

I'd like to create a macro and have it run automatically that will hide any row that has a date in column A that is 7 days or older. In this case, if I open the workbook on 4/15/14, the macro would hide rows 3 thru 10, upon opening.

Please help.

Thanks,
EVT123

Summary report, auto copy /insert

$
0
0
Hello
I am trying to do a summary of multiple sheets that will update as new data is keyed in.

Example Daily Overtime report TEST..xlsx

Please refer to attachment. What I would like to do is key information onto sheet "CREW 1" and any row that contained information would be copied and inserted onto the summary sheet under the corresponding header automatically.
Any help is greatly appreciated
Thanks

What does on error resume next mean?

$
0
0
What does on error resume next mean? And also, what does err.clear mean?

Code:

On Error Resume Next
Worksheets("PaySchedule").Delete
Err.Clear
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "PaySchedule"

Help me with Cumulative formula and payback period VBA

$
0
0
I have no idea on how to write a cumulative formula and payback period using VBA would you guys help?
Attached Files
Viewing all 50026 articles
Browse latest View live