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

[SOLVED] default sheet show every open ?

$
0
0
How to set the sheet 1 us my default. every time i open my excel file it will go in sheet 1 and hide the sheet 2 and then the userform2 will show and then type the password i set. when the password type correctly i will unhide the sheet and you will transfer in sheet 2 ??? Thanks for the Help.
Attached Files

Documentation Regarding CreateObject("Wscript.Shell")

$
0
0
Hi,

I use a few codes that use CreateObject("Wscript.Shell")

However, I do not know what exactly that is or how is it used.

Can anyone point me in the right direction for learning more about it?

Updating Formula

Automatic capital letter for each sentence First letter - how

$
0
0
Hi

in excel if i write a word in a column how to get the first letter automatically to capital.
if i write a sentence in excel the first letter of that sentence should come as uppercase

please support

Comparing Columns and Copy entire row

$
0
0
I want to compare two worksheets to generate result if found duplicate.. attached sample.xls sheet("report") show the required data..
we only have to compare Cus sheet column F with Emp Sheet column G and get the employees details..
Any help using formulas or macros will be highly appreciated..
Attached Files

VLoookup or If Statement

$
0
0
Hi,

I'm a wee bit stuck, I did a bit of coding at uni (many years ago) but now it's like I'm starting from scratch.

I'm trying to design a simple spread sheet for a manufacturing environment

Filter data and copy visible cells based on criteria

$
0
0
Hello everyone

Hope everyone is fine
In my attachment I have Data sheet .. I need first to filter column D according to the value in range("I1") then the visible results would be copied to specific sheets in order (01A then 02A then 03A .. That's sheets have the letter A to the right)
Copying the visible cells would be 29 records for each page

For example : I have filtered the data and got 38 record ..
so in sheets("01A") I expect to have the first 29 names
then in sheets("02A") there would be just 9 records to be copied
of course sheets("03A") would be empty with no names as the results are out ..

In target sheets (01A,02A,03A) I need first before running the code to clear the contents of the ranges (C6:C1000) as a preparation to receive the new results


the copied data would be column B only .. the target cell in target sheets would be cell C6
Hope it is clear
Attached Files

VBA not getting the data

$
0
0
Code:

Sub Extractdatafromwebsite()
Dim ie As New InternetExplorer
Dim Ticker As String
Ticker = Sheet1.Range("B1").Value
ie.Visible = True
ie.navigate "http://finance.yahoo.com/q?s=" & Ticker
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Set doc = ie.document
On Error Resume Next
doc.getElementById("yfs_l84_" & Ticker).innerText
Sheet1.Range("B2").Value = output
ie.Quit
End Sub

I load the macro to get me current stock price according to the ticker but nothing happens, it just open the stock's webpage. Could anyone explain the problem?

Hide rows based on range of cells.

$
0
0
I have the following spreadsheet that tracks hours for weeks ending (much larger both ways obviously):
A B C D E
1 Name 15-Nov 22-Nov 29-Nov 6-Dec
2 Joe Blow 40 40 40

I've been trying to come up with a macro that will hide specific rows where ALL cells in a given range are blank. For example, if cells B2, C2 and D2 are blank, hide that row. The ranges will always be consecutive and I usually have a filter based on data in a specific row (not one of these of course). In my extremely rudimentary excel experience, this is what I was thinking:

If Range (B2:D2).Value = "" Then
Row("3").EntireRow.Hidden = True
Else
Row("3").EntireRow.Hidden = False
End If
Next
End Sub

But I have to be way off. None of the examples I've tried by the Google method worked either. Can anyone suggest something?

Thanks so much in advance and look forward to browsing the site (new member eager to learn!)

Late binded VBA Code working in Excel 2013 but not Excel 2010

$
0
0
The following late binded code works in Excel 2013 but doesn't work in Excel 2010. I think I may have late binded it wrong. Essentially, the code pulls e-mail dates and sender e-mail address from Outlook and populates it in Excel.



Here's my attempt at late binding this piece of code:

Early bound version

Quote:

Dim olApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem
Dim eFolder As Outlook.Folder
Dim i As Long
Dim wb As Workbook
Dim ws As Worksheet
Dim iCounter As Long
Dim lrow As Long

Set wb = ActiveWorkbook
Set ws = wb.Worksheets("vlookup")

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")

wb.Sheets("vlookup").Range("A2:C500").ClearContents

'i think you want column E here, not L?
lastRow = ThisWorkbook.Worksheets("vlookup").Cells(Rows.Count, "E").End(xlUp).Row

For Each eFolder In olNs.GetDefaultFolder(olFolderInbox).Folders
Set olFolder = olNs.GetDefaultFolder(olFolderInbox)
For i = olFolder.Items.Count To 1 Step -1

If TypeOf olFolder.Items(i) Is MailItem Then
Set olMail = olFolder.Items(i)
For iCounter = 2 To lastRow
If InStr(olMail.SenderEmailAddress, ws.Cells(iCounter, 5).Value) > 0 Then 'qualify the cell
With ws
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("C" & lrow + 1).Value = olMail.Body
.Range("B" & lrow + 1).Value = olMail.ReceivedTime
.Range("A" & lrow + 1).Value = olMail.SenderEmailAddress
End With
End If
Next iCounter
End If
Next i
Set olFolder = Nothing
Next eFolder


End Sub
From what I've scoured from the net, the following are the only changes I need to make.

Late bound version

Quote:

Dim olApp As Object
Dim olNs As Object
Dim olFolder As Object
Dim olMail As Object
Dim eFolder As Object
Dim i As Long
Dim wb As Workbook
Dim ws As Worksheet
Dim iCounter As Long
Dim lrow As Long

Set wb = ActiveWorkbook
Set ws = wb.Worksheets("vlookup")


Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
My problem:

It runs on my Excel 2013 but doesn't work on Excel 2010. There's no code error, but Nothing populates.

I've gone into Tools --> References, unclicked the MISSING 15.0 objects and clicked 14.0 Objects library for Excel/Outlook/Office, and when I run it there's no errors or anything BUT nothing happens

ANy help is greatly appreciated, thanks!

Need some assistance with creating a Payment Summary Sheet with VBA

$
0
0
I am somewhat familiar with Excel but am brand new to VBA Macros, I am currently trying to make a sheet that can be used to enter payments made by numerous members and I have that mostly working well I think. Where I am hitting a road block is to take all applied payments and summarize them in Sheet 2 where I want it to show Member Names in Column A with 2 rows assigned to each member where a Date is entered in the top row and a payment amount in the 2nd row. In Sheet 1 I can select a name, enter a payment and date, and then hit the command button which copies the formulas in G8 thru G22 and then pastes it "Values Only" in E8 thru E22. It then does the same with the date formulas in H8 thru H22 and pastes the same way in C8 thru C22. Where I am asking for help is in populating Sheet 2 with the correct information each time the macro is used. I have attached a copy of the sheet I am working with and am grateful for any help I can get.

Thanks!
Excel Test Copy.xlsm

Call a macro when a cell value changes by a formula

$
0
0
Please help me on this code that runs a macro everytime a cell in a range for example Sheet1("A1:A10") changes by a formula, the dependents of this formulas are in another sheet (Sheet2), i tried the code below but this code works only if the dependents are in the same sheet

Code:

Private Sub Worksheet_Change(ByVal target As Excel.Range)
On Error GoTo GetOut
If Not Application.Intersect(target.Dependents, Range("A1:A10")) Is Nothing Then
MsgBox "Hello"
End If
GetOut:
End Sub

Thanks in advance!

Copy value of merged cell to another cell.

$
0
0
Hello,

I created a automatic schedule (year, months, weekends and holidays) and I want to copy a value that is in merged cell (ex. G20) to another cell that must obtain that value via Excel Formula, our another way. For example, like in the picture, when I enter a value in cell G20 (A), I want it to automatically update the cell G13 (with A) and so on.

Any help will be very appreciated.

Schedule.JPG

Regard's
FS

Use Solver or VBA to calculate EOQ based on many price options to minimize costs

$
0
0
Hi All,

I have a big challenge here... I want to create a tool that can help me find the best order quantity for each product based on the Economic Order Quantity formula
"EOQ = SQR [[(2*Annual Forecast)*(Order Cost + Inspection Cost (IN MY CASE))]/ Carrying Cost per UN]

The problem Is that there are too many moving parts, I'm trying to find the best order quantity that will minimize my total costs "TC = ordering cost + Purchase price(Total) + Inspection Cost + Inventory Holding Cost

The EOQ formula assumes the price and processing (inspection) don't change, but in real life they do based on the quantity
I'm trying to figure out if there is a way to use solver or VBA to calculate the optimal order quantity (I entered some estimates in the attached file by item however the order quantity doesn't need to be one of those options, yet the inspection cost does depends on the thresholds set and the approximate price change % is estimated based on the quantities I entered)

I have added more explanations at the top right of the sheet in yellow. If the file is too big to send back feel free to delete lines from it.

Thank you!
Attached Files

Clone Excel Sheet Structure but Change Cell Values

$
0
0
Hello all

So there's a TL;DR (Too long - didn't read) here which is a summary...
_______________________________________
TL;DR

I want to find a way, via macro / vba to do this........
- "Search for cell values that aren't a formula in Worksheet 1"
- "Select those values"
- "Find a column in Worksheet 2 with the same column heading (Row 1) and row reference (column A) as the cells selected in Worksheet 1"
NOTE - these may have moved
- "Paste Values and number formats in the right places"
- "Keep everything else as a formula and leave it alone"

..... or this:
- Have Worksheet 1 and Worksheet 2 dynamically linked - changes to structure (i.e. add columns, remove columns, add rows, re-arrange columns) and certain cells (i.e. Column A:A, and Rows 1:5) in "Worksheet 1" are automatically picked up on "Worksheet 2"... But all values within a certain range (i.e. B6:AZ2000) in Worksheet 2 are calculated by a formula from the values of Worksheet 1... but the user can manually override any values in "Worksheet 2" that they please.
______________________________________________________________

I've got a very interesting, and hopefully, solveable problem.

I have developed a water balance spreadsheet. In this spreadsheet I have 2 tabs - "Flow Meter Entry" and "Flow Meter Monthly".
- "Flow Meter Entry" holds information on flow meters that measure how much water has travelled around a mine - i.e. one month the meter will read 10,000. The next month the meter will read 11,000.
- "Flow Meter Monthly" does the sum to calculate how much water has moved through the flow meter in that month - i.e. 11,000 - 10,000 = 1,000. It's done with a very large nested IF statement to catch a whole heap of errors that may occur etc.


The data are arranged in columns - i.e. each date is a new row, and each flow meter is a new column. There are about 30 flow meters in total, and the columns are grouped (put beside each other) by type (i.e. some that measure potable water, some that measure mine water, some that measure greywater etc.). There are a whole heap of Conditional Formatting Rules in the "Flow Meter Monthly" tab as well.

I've developed this spreadsheet so that people who are not great at excel, can just plug in the "Total numbers" that they read off the flow meters, and it will automatically calculate how much water has gone through the flow meter between dates.

Now the problems:
a) the mine site will want to add new flow meters as they install them (i.e. add a new column in the midst of existing columns)
b) sometimes on the "Flow Meter Monthly" tab, the site will have to manually enter values instead of relying on the formula (for a variety of reasons).

I want the 2nd excel sheet, "Flow Meter Monthly" to pick up on changes done to the structure of "Flow Meter Entry" so that if a new column is added in the middle of data, it is automatically done in "Flow Meter Monthly".

The only way I've come up with to do this is to make a macro and edit the VBA Code so that, that, when it is activated (when the user hits a button after entering data on "Flow Meter Entry"), the following happens:
- The entire worksheet of Flow Meter Entry is copied to a new workbook (Flow Meter Entry (2))
- The nested IF statement calculation is applied to all relevant cells
- All formula results in the "Flow Meter Entry (2)" are copied and pasted as values (just because)

I then want to make it, so in said macro, the sheet "Flow Meter Monthly" is deleted, "Flow Meter Entry (2)" is renamed to "Flow Meter Monthly" and then a whole heap of conditional formatting is applied.... but the problem is that I want any manual changes to the values in the original "Flow Meter Monthly" (i.e. manually overridden cells) to be picked up and put in the relevant column (which may have moved) of the "Flow Meter Entry (2)". So essentially is there a way in VBA to go
- "Search for cell values that aren't a formula in Worksheet 1"
- "Select those values"
- "Find a column in Worksheet 2 with the same column heading as the cells selected in Worksheet 1"
- "In Worksheet 2, Find the row reference (date) with the same row reference (date) as Worksheet 1"
NOTE - these may have moved
- "Paste Values and number formats"
- "Keep everything else as a formula and leave it alone"

If I can do that, then I'll get the macro to keep on going and delete "Flow Meter Monthly" and re-name "Flow Meter Entry (2)" to "Flow Meter Monthly" and it's all sorted - I just have to be sure that I can pick up the manually over-ridden values put in "Flow Meter Monthly" by other people at the mine site, and incorporate them into "Flow Meter Entry (2)" before deleting the old worksheet.

...............
Alternatively if there's a way to have "Flow Meter Monthly" as a clone of "Flow Meter Total" so that if a column is added or moved in "Flow Meter Total" it is also added or moved in "Flow Meter Monthly" etc... but the values in certain cells are calculated based on a formula in "Flow Meter Monthly" from the values in the cells of "Flow Meter Total" (and can be manually overriden).

_____________________________________

Any help on this would be GREATLY appreciated. I've only got very basic skills in VBA (I record a macro in excel, then go into VBA, try to understand what's going on (most of the time its not hard) and change things to make it work for me (i.e. worksheet names based on a cell value, save worksheet as a PDF with a file name based on cell values, etc.)

Cheers

Reece

UserForm and calling different macros

$
0
0
Hello
I have created an excel workbook with a number of worksheets. I have also created a userform1 from excel developer where all the worksheets are visible in a menu, each worksheet has a checkbox against it, each worksheet has a separate small macro. When a user opens the workbook they are presented with this menu, the idea is when the worksheet is selected in the menu it will run the macro associated with that worksheet but how do I call the macro when the worksheet is selected in the menu.
• The user is presented with the menu
• The user will physically go the tab in the worksheet and fill in some data, there may be more than one worksheet to update.
• The user returns to the menu I created and selects the worksheets which will run the macro, each worksheet has a different macro but I have managed to get them working just need help on the calling them from the menu(userform) part. I thought about going to each worksheet and placing a macro button on it and assigning it to the macro however I think this would look professional.
This code behind the userform is below, it allows me to select the sheet but having problems calling the associated macro once the sheet is selected

Any help will be appreciated

Sub OKButton_Click()
Dim i As Integer, MaxItem As Integer
Dim outputstring As String
Dim itemselected As Boolean

MaxItem = Me.SheetSelector.ListCount - 1

With Me.SheetSelector
For i = 0 To MaxItem
itemselected = .Selected(i)
If ((Me.IncludeSelected And itemselected) Or Me.IncludeAll) Then
outputstring = outputstring & "," & Me.SheetSelector.List(i)
ElseIf (Me.ExcludeSelected And (Not itemselected)) Then
outputstring = outputstring & "," & Me.SheetSelector.List(i)
End If
Next
End With
MsgBox Mid(outputstring, 2)
End Sub

Sub UserForm_Initialize()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Me.SheetSelector.AddItem ws.Name
Next
Me.IncludeSelected = True
End Sub

UserForm to print report for month/year

$
0
0
I have a userform that prints a monthly report from a commandbutton. This is picked from the sheet where the userform send the data to. This sheet is designed to run for multiple years. At the moment the command button prints the month but this is because this is the first year of operation.
Is it possible to code in the month and year plus 14 days to allow time to print the last month?
This is the current code:
HTML Code:

Sub August_Click()
   
    Dim Destrange As Range
    Dim Smallrng As Range
    Dim Newsh As Worksheet
    Dim Monthly As Worksheet
    Dim Lr As Long
   
    Set Monthly = ActiveSheet
    Set Newsh = Worksheets.add
    Monthly.Select

    Lr = 1
   
    Monthly.Range("$A$2:$A$28,$I$2:$I$28").Select  'Change printing area or you can use input box
    For Each Smallrng In Selection.Areas
        Smallrng.Copy
        Set Destrange = Newsh.Cells(1, Lr)
        Destrange.PasteSpecial xlPasteValues
        Destrange.PasteSpecial xlPasteFormats
        Lr = Lr + 1
    Next Smallrng

    Newsh.Columns.AutoFit
    With Newsh.PageSetup
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = 1
    End With
    Newsh.PrintOut
   
    Application.DisplayAlerts = False
    Newsh.Delete
    Application.DisplayAlerts = True

End Sub

Table that calculates F2 from all filled cells but not empty cells.

$
0
0
Hello!
I'll try my best to describe my issue.
My boss told me to create Excell Spreadshit that calculates statistics (F2, rsd, etc.) from filled cells but not empty ones.
E.g. you can enter any amount of data but calculation will use only cells with info.
If you use simple formula, you have to specify range to be used. I want to eliminate this so range is infinite but empty spaces are not counted.

Do you recommend to stop macro at last filled cell or before first empty cell? And how to make it calculate stuff from those filled cells?

Please, help, I'm new to VBA

Thank you

[SOLVED] Table in Message Box

$
0
0
I have a table tblCodes as below:
Country Codes
Australia AUD
Brunei Darussalam BND
Cambodia KHR
China CNY
European Union EUR
Great Britain GBP
Hong Kong HKD
Indonesia IDR
Japan JPY
Korea-South KRW
etc
The table is on a worksheet called Lists. I want to add a button to display a message box on the input sheet that displays the table to aid the data encoder add the correct code.
Is this possible and what is the vb code if it is ?

[SOLVED] How to check if a cell contains a specific string from a variable?

$
0
0
Say for example,

Cells(x,y).value = "ABC 123 BOB XYZ"

and I have a string variable called vName = "Bob"

I would like to check to see if the cells(x,y) contains vName and return true or false. In my example, this should return true. How do I go about making that if statement? Thanks
Viewing all 49975 articles
Browse latest View live